Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

XML
<pre lang="xml">
<content_item>
      <title><![CDATA[One]]></title>
      <subtitle><![CDATA[IN HOUSE]]></subtitle>
      <extra_previews>
        <preview2_url><![CDATA[http://abc/1.png]]></preview2_url>
        <preview2_url><![CDATA[http://abc/2.png]]></preview2_url>
        <preview2_url><![CDATA[http://abc/3.png]]></preview2_url>
      </extra_previews>
</content_item>
</pre>


SQL
Note: I'm able to read only first row (1.png) only. after read first row it exit from loop.
How to read 2nd & 3rd row
My code as below:


var res = (from c in xe.Descendants("extra_previews")
                      select (XElement)c).ToList();
I got result in "res" as below

      <extra_previews>
        <preview2_url><![CDATA[http://abc/1.png</preview2_url>
        <preview2_url><![CDATA[http://abc/2.png</preview2_url>
        <preview2_url><![CDATA[http://abc/3.png</preview2_url>
      </extra_previews>

I'm trying to read "preview2_url" Elements below:

List<clsExtraPreviews> extraPrev = new List<clsExtraPreviews>();
 clsExtraPreviews ObjRec;
            foreach (var p in res)
            {
                ObjRec = new clsExtraPreviews();
                ObjRec.preview2_url = p.Element("preview2_url").Value;
                extraPrev.Add(ObjRec);
            }



Br,
Siddheshwar
Posted

1 solution

Hi,

I have resolved myself.

XML
List<clsExtraPreviews> extraPrev = new List<clsExtraPreviews>();
            IEnumerable<XElement> inner = xe.Elements("extra_previews").Elements("preview2_url");

            clsExtraPreviews ObjRec;
            foreach (var p in inner)
            {
                ObjRec = new clsExtraPreviews();
                ObjRec.preview2_url = p.Value;
                extraPrev.Add(ObjRec);
            }
 
Share this answer
 
v2

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