Import XML into Dataset C#
dataset, xml
Solution
As soon as you define your XML namespace used in the XML elements, you can easily import this - no problem.
You need to have your XML look something like this:
<Catalog xmlns:dt="some-xml-namespace-here">
<Rec>
<ITEM dt:dt="string"/>
<QTY dt:dt="string">1</QTY>
<SUB dt:dt="string">1</SUB>
<CATALOG dt:dt="string">ABC123</CATALOG>
</Rec>
.....
</Catalog>
After I do this, your two lines of code work like a charm and the data gets imported, no problem (into 5 tables inside the DataSet).
Marc
Problem
I am trying to get a xml file into a dataset and am using the following code: ``` DataSet ds = new DataSet("TestDataSet"); ds.ReadXml(FileName); ``` and this xml file: ``` <Catalog> <Rec> <ITEM dt:dt="string"/> <QTY dt:dt="string">1</QTY> <SUB dt:dt="string">1</SUB> <CATALOG dt:dt="string">ABC123</CATALOG> </Rec> <Rec> <ITEM dt:dt="string"/> <QTY dt:dt="string">1</QTY> <SUB dt:dt="string">1</SUB> <CATALOG dt:dt="string">ABC124</CATALOG> </Rec> <Rec> <ITEM dt:dt="string"/> <QTY dt:dt="string">1</QTY> <SUB dt:dt="string">1</SUB> <CATALOG dt:dt="string">ABC125</CATALOG> </Rec> </Catalog> ``` The trouble is that the after setting a watch on ds, it only appears to contain a table called Rec and a column called Rec_Id. If I remove the "dt:dt="String"" datatype everything works fine. I am using C#.net 2008... Can someone please advise of the correct way to import this data without having to alter the xml file? Thanks