Vipul Kelkar

Vipul Kelkar

  • NA
  • 1.9k
  • 559.4k

Linq to XML. Select particular descendants.

Jan 3 2013 1:00 AM

Hi All,

I have the following XML

<XMLNODE_1 attr1="" attr2="">

    <XMLNODE_2>

               <XMLNODE_3></XMLNODE_3>

               <XMLNODE_3></XMLNODE_3>

               <XMLNODE_3></XMLNODE_3>

               <XMLNODE_4>

                              <XMLNODE_3>

                              <XMLNODE_3>

               </XMLNODE_4>

    <XMLNODE_2>

</XMLNODE_1>


I have got the XElement of XMLNODE_2 in an object. When i execute 

xmlnode2.Descendants("XMLNODE_3");

I get all the XMLNODE_3 tags ie 5 (includes the nodes under XMLNODE_4 also)

How can I get the XMLNODE_3 nodes which are only under XMLNODE_2 and NOT under XMLNODE_4



Answers (1)