XmlDocument SelectNodes(Xpath): Order of result

Posted by crauscher on Stack Overflow See other posts from Stack Overflow or by crauscher
Published on 2010-03-30T10:23:05Z Indexed on 2010/03/30 10:43 UTC
Read the original article Hit count: 624

Filed under:
|
|
|

This is an example xml from MSDN

<?xml version="1.0"?>
<!-- A fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
  <book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
    <title>Pride And Prejudice</title>
  </book>
  <book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
    <title>The Handmaid's Tale</title>
  </book>
  <book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
    <title>Emma</title>
  </book>
  <book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
    <title>Sense and Sensibility</title>
  </book>
</bookstore>

When I select all book nodes using the following code, which order will these nodes have?

XmlDocument doc = new XmlDocument();
doc.Load("booksort.xml");

var nodeList =doc.SelectNodes("bookstore/book");

Will the order of the items in the nodelist be the same as the order in the xml? Is this order guaranteed?

© Stack Overflow or respective owner

Related posts about c#

Related posts about xpath