Question:
Using VB.NET/C#, is it really not possible to read the below XML in a dataset without significant work ?
I tried
oDataSet.ReadXml(strFileName)<BR>
and
Dim oDataSet As System.Data.DataSet = New System.Data.DataSet
Dim strLocation As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
strLocation += System.IO.Path.DirectorySeparatorChar + "filename.xml"
oDataSet.ReadXml(strLocation)
But all this is doing is putting ONE row with one cell with content “2010-02-12T10:33:39” in my dataset…
This is driving me crazy…
This is the XML file:
<?xml version="1.0" encoding="UTF-8"?>
<dataroot generated="2010-02-12T10:33:39">
<Employee>
<MI_KZ>HKBZV</MI_KZ>
<MI_Name>Doe</MI_Name>
<MI_Vorname>John</MI_Vorname>
<MI_Nummer>70642860</MI_Nummer>
<MI_DatumVon>2010-02-11T10:45:37</MI_DatumVon>
<MI_DatumBis>2010-03-13T00:00:00</MI_DatumBis>
<AP_Bezeichnung>5-B-03</AP_Bezeichnung>
<KOE_Code>FHBM</KOE_Code>
<KST_Code></KST_Code>
<KST_Kurz><![CDATA[]]></KST_Kurz>
</Employee>
<Employee>
<MI_KZ>EX2FC</MI_KZ>
<MI_Name>Doe</MI_Name>
<MI_Vorname>Judith</MI_Vorname>
<MI_Nummer>70642680</MI_Nummer>
<MI_DatumVon>2010-02-10T14:12:56</MI_DatumVon>
<MI_DatumBis>2010-06-01T00:00:00</MI_DatumBis>
<AP_Bezeichnung>Gotth.</AP_Bezeichnung>
<KOE_Code>UEU</KOE_Code>
<KST_Code></KST_Code>
<KST_Kurz><![CDATA[]]></KST_Kurz>
</Employee>
<Employee>
<MI_KZ>EX0GW</MI_KZ>
<MI_Name>Testname</MI_Name>
<MI_Vorname>Testprename</MI_Vorname>
<MI_Nummer>70038630</MI_Nummer>
<MI_DatumVon>2004-05-11T00:00:00</MI_DatumVon>
<MI_DatumBis>2010-08-16T00:00:00</MI_DatumBis>
<AP_Bezeichnung>SempSee</AP_Bezeichnung>
<KOE_Code>KFMP</KOE_Code>
<KST_Code></KST_Code>
<KST_Kurz><![CDATA[]]></KST_Kurz>
</Employee>
</dataroot>
Datasets can have more than one table you know… try looking at a different table.
Beyond that, the
ReadXml()method is really intended for reading xml that was written out with another Dataset’sWriteXml()method.To read arbitrary xml, you should use the xsd.exe program that ships with Visual Studio on a sample xml file. The first pass of this will create a *.xsd schema file for your xml. Then run the tool again on this xsd schema file with the correct options (sorry, don’t have visual studio on this machine to check right now) and it will create either a typed dataset, C# class file, or VB.Net class file that you can use to “deserialize” your xml data.