Click here to Skip to main content
15,886,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have requirement whereby I have to read specific tags from XML and convert it to dataset. I have written a code but its ignoring some tags which i want to consider.

(some tags have attribute while some dont)

Eq: I need <row> tag with <c99> and <c100> tags from below xml rest all tags can be ignored.(Need dataset)

Note:my code is ignoring <c99> and <c100> whis is my requirement

HTML
<row id="0110398750012">
<c1>10398235475</c1>
<c2>1050</c2>
<c99 m="2">LEGACY</c99>
<c99 m="3">T24.IBAN</c99>
<c99 m="4">PREV.IBAN</c99>
<c100 />
<c100 m="2">100119406</c100>
<c100 m="3">asdsafsaf</c100>
<c100 m="4">afafsafaff</c100>
<c108>NO</c108>
<c141>NO</c141>
<c167>20160205</c167>
<c203>2</c203>
<c204>afffghhjjjgfj</c204>
<c205>sdfdfsdfdsfds</c205>
<c206>ssdfdfdf.READ.sdff</c206>
<c207>sdfdfdfdsf</c207>
<c208>1</c208>
</row>


What I have tried:

C#
XDocument xdoc = XDocument.Load(sourcexml); // or XDocument.Parse(string)

                xdoc.Root.Descendants().Where(e => e.Name != "c1" && e.Name != "c2" && e.Name != "c27" && e.Name != "c122"
                    && e.Name != "c8" && e.Name != "c78" && e.Name != "c90" && e.Name != "c7" && e.Name != "c100"
                    && e.Name != "c202" && e.Name != "c13").Remove();


                reader = new XmlNodeReader(XMLutility.ToXmlDocument(xdoc));

                DataSet ds = new DataSet();
                ds.ReadXml(reader);
Posted
Updated 4-Apr-16 20:01pm
v3

1 solution

 
Share this answer
 

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