looping through parent child combination xml using c#
I am new to xml, i want to looping through the below xml and save the records in the database. the below xml is parent child c开发者_StackOverflow中文版ombination, parts as to be saved under respective parents. if the source field is M then there will be child item for that.
<PARENT>
<COMPONENT>
<part>test1</part><source>M</source><ParentPart>parent</ParentPart>
<SUBCOMPONENT>
<part>test2</part><source>B</source><ParentPart>test1</ParentPart>
</SUBCOMPONENT>
<SUBCOMPONENT>
<part>test3</part><source>M</source><ParentPart>test1</ParentPart>
<SUBSUBCOMPONENT>
<part>test4</part><source>B</source><ParentPart>test3</ParentPart>
</SUBSUBCOMPONENT>
</SUBCOMPONENT>
</COMPONENT>
<COMPONENT>
<part>part1</part><source>B</source><ParentPart>parent</ParentPart>
</COMPONENT>
<COMPONENT>
<part>part2</part><source>M</source><ParentPart>parent</ParentPart>
<SUBCOMPONENT>
<part>part3</part><source>B</source><ParentPart>part2</ParentPart>
</SUBCOMPONENT>
<SUBCOMPONENT>
<part>part4</part><source>M</source><ParentPart>part2</ParentPart>
<SUBSUBCOMPONENT>
<part>part5</part><source>B</source><ParentPart>part4</ParentPart>
</SUBSUBCOMPONENT>
</SUBCOMPONENT>
</COMPONENT>
</PARENT>
any help would be appropriated.
Thanks,
Pradeep
You have a lot of options here: - if you have xml schema, use xsd.exe which generates classes you fillup with XmlSerializer. - XmlDocument allows you to do XPath queries. - consider XmlTextReader if your files are large and you need fast proccesing.
精彩评论