<STRUS name="AB" lineStart="3" lineEnd="33"> <SVALUs> <SVALU name="TREE" line="33"><segment id="SE" xml:space="preserve"><element pos="1">34</element><element pos="2">100550212</element></segment></SVALU> </SVALUs> <STRUS name="1000A" lineStart="5" lineEnd="6"> <SVALUs> <SVALU name="ZRT" line="5"><segment id="NM1" xml:space="preserve"><element pos="1">41</element>...<element pos="9">PCCARE</element></segment></SVALU> <SVALU name="PER" line="6"><segment id="PER" xml:space="preserve"><element pos="1">IC</element>...<element pos="4">12345678</element></segment></SVALU> </SVALUs> </STRUS> </STRUS> <STRUS name="AB" lineStart="34" lineEnd="54"> <SVALUs> <SVALU name="TREE" line="35"><segment id="SE" xml:space="preserve"><element pos="1">34</element><element pos="2">100550212</element></segment></SVALU> </SVALUs> <STRUS name="1000A" lineStart="35" lineEnd="36"> <SVALUs> <SVALU name="ZRT" line="37"><segment id="NM1" xml:space="preserve"><element pos="1">41</element>...<element pos="9">TCOWS</element></segment></SVALU> <SVALU name="PER" line="38"><segment id="PER" xml:space="preserve"><element pos="1">IC</element>...<element pos="4">12345678</element></segment></SVALU> </SVALUs> </STRUS> </STRUS>
Dim xDoc As XDocument = XDocument.Load("E:\Some.xml") Dim root As XElement = xDoc.Root ' Get the Node have STRU name="AB" Dim STElems = From x In root.Descendants("STRUS") _ Where (x.Attribute("name").Value = "AB") _ Select x ' Iterate through each AB Node For Each STElem As XElement In STElems 'How do you extract (PCCARE) for the node for line 18 where pos = 9 'Tried this but know it doesn't work: Dim elements9 = From e In STElem.Descendants("SVALU") _ Where (e.Attribute("pos").Value = "9") And (e.Attribute("name").Value = "ZRT") _ Select e.Value Dim ValueStr as STring = ????? 'First loop returns PCCARE and then second iteration returns TCOWS Next
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)