Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been trying to read a XML with the following structure

XML
<TopNode>
<SubNodeType1 Data2="Val2" Data1="Val1"/>
<SubNodeType1 Data2="Val2" Data1="Val1"/>
.
.
n
.
<SubNodeType1 Data2="Val2" Data1="Val1"/>
<SubNodeType2 Data2="Val2" Data1="Val1" Data4="Val4" Data3="Val3"/>
<SubNodeType2 Data2="Val2" Data1="Val1" Data4="Val4" Data3="Val3"/>
</TopNode>


If i try to read this XML data i am able to see all the data from SubNodeType1 in the dataset.

Question is that can i override the dataset to receive all the data in the same dataset. Or any other way in which i can read SubNodeType1 and SubNodeType2 into 2 different datasets?

What I have tried:

C#
XmlDocument xmlFile = new XmlDocument();
xmlFile.Load(strXMLFilePath);
XmlNodeReader xmlReader = new XmlNodeReader(xmlFile);
DataSet ds = new DataSet();
ds.ReadXml(xmlReader, XmlReadMode.InferSchema);
Posted
Updated 29-Jun-16 11:41am
v3
Comments
BillWoodruff 30-Jun-16 0:48am    
So, who/what created this XML, and designed its structure ? You ? It appears to lump together two different Types. If you add an example of the code that generates this XML, you might get better responses.
Rishav Prabhakar 30-Jun-16 13:51pm    
Well this is a suppliers XML format. Information regarding generation of file is not accessible to me.
If i can get SubNodeType1 and SubNodeType2 in 2 different datasets, I can work with that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900