这是来自MSDN的示例xml ?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" titlePride And Prejudice/title /book book
<?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>
当我使用以下代码选择所有书籍节点时,这些节点将具有哪个顺序?
XmlDocument doc = new XmlDocument(); doc.Load("booksort.xml"); var nodeList =doc.SelectNodes("bookstore/book");
nodelist中项目的顺序是否与xml中的顺序相同?这个订单有保证吗?
是.在反射器中查看它,此方法最终使用XPathNodeIterator,该文档记录为按文档顺序迭代. http://msdn.microsoft.com/en-us/library/1212yhbf.aspx