none
XPath: selectnodes does not return declaration or comment RRS feed

  • Question

  • In this example:

    <?xml version='1.0'?>
      <bookstore xmlns="urn:newbooks-schema">
        <book genre="novel" style="hardcover">
          <title>The Handmaid's Tale</title>
          <author>
            <first-name>Margaret</first-name>
            <last-name>Atwood</last-name>
          </author>
          <price>19.95</price>
        </book>
        <book genre="novel" style="other">
          <title>The Poisonwood Bible</title>
          <author>
            <first-name>Barbara</first-name>
            <last-name>Kingsolver</last-name>
          </author>
          <price>11.99</price>
        </book>
        <book genre="novel" style="paperback">
          <title>The Bean Trees</title>
          <author>
            <first-name>Barbara</first-name>
            <last-name>Kingsolver</last-name>
          </author>
          <price>5.99</price>
        </book>
      </bookstore>

    I try to read all nodes with:

     Public Function getAllNodes() As XmlNodeList
             getAllNodes = XDoc.SelectNodes("//*")
             'Is idem:
             'getAllNodes = XDoc.SelectNodes("descendant::*")
     End Function

    It works fine, but it does not return the declaration tag nor does it return (in other xml-files) the comment tag.

    These tags I get with looping through something like

    dim xmlKnoten as xml.xmlnode
    For Each xmlKnoten In XDoc.ChildNodes  
    Why is this so?

    Saturday, May 31, 2014 7:55 AM

Answers