Answered Linq to XML. Select particular Descendants

  • Thursday, January 03, 2013 4:29 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

All Replies