的XmlDocument的SelectNodes(的XPath):结果令 [英] XmlDocument SelectNodes(Xpath): Order of result
本文介绍了的XmlDocument的SelectNodes(的XPath):结果令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是从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");
将在节点列表中的项目的顺序是一样的,在XML的顺序?这是为了保证?
Will the order of the items in the nodelist be the same as the order in the xml? Is this order guaranteed?
推荐答案
是的。在反光看它这个方法最终使用声明XPathNodeIterator
这是记录在文档顺序进行迭代。 http://msdn.microsoft.com/en-us/library/1212yhbf.aspx
Yes. Looking at it in reflector this method ends up using an XPathNodeIterator
which is documented to iterate in document order. http://msdn.microsoft.com/en-us/library/1212yhbf.aspx
这篇关于的XmlDocument的SelectNodes(的XPath):结果令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文