I have following xml:
<TextWithNodes><Node id="0" />astralis<Node id="8" /> <Node id="9" />ltd<Node id="12" />
<Node id="14" />{<Node id="15" />DOCUMENT<Node id="23" />}<Node id="24" /> <Node id="25" />{<Node id="26" />TYPE<Node id="30" />}<Node id="31" />EX-<Node id="34" />10<Node id="36" />.<Node id="37" />12<Node id="39" /> <Node id="40" />{<Node id="41" />SEQUENCE<Node id="49" />}<Node id="50" />3<Node id="51" /> <Node id="52" />{<Node id="53" />FILENAME<Node id="61" />}<Node id="62" />e<Node id="63" />300201<Node id="69" />_<Node id="70" />ex<Node id="72" />10<Node id="74" />-<Node id="75" />12<Node id="77" />.<Node id="78" />txt<Node id="81" /> </TextWithNodes>
and I need to pick node from Id 25 to id 75. It is a portion of XML. Original XML is very long. How to do it without XPath?
Dim nodeList As XmlNodeList = xmlDoc.SelectNodes("//Node[@id >" & 25 & " and @id <" & 75 & "]")
Dim sb As StringBuilder = New StringBuilder
For Each childNode As XmlNode In nodeList
sb.Append(childNode.InnerText)
Next
but it is not working …
Please suggest.
Thanks
[This is too long for a comment, so…]
Reformatting the start of the XML:
shows that node of the
Nodeelements have no content; rather the content is between the elements. So when you say:do you want just the
Nodeelements, or all the sibling XML DOM nodes – both elements and text – between the two identifiedNodeelements, or just theNodeelements?Answer: XPath thanks to this answer:
which makes use of an empty node set being false: nodes before
id="25"will have an emptypreceding-sibling::...node set, similarly for the nodes afterid="75".