此代码打印出来book1book2
。我只是想让它打印出来book2
。我没有正确指定谓词吗?
(请注意,我并不是真的在寻找打印出“book2”的替代方法,因为这是对我的问题的简化——我更希望了解我在学习 c# 时做错了什么)。
using System.Xml;
using System.Xml.XPath;
using System.IO;
String xpathStg =
"<bookstore> <book>book1</book> <book>book2</book> </bookstore>";
XPathDocument docNav = new XPathDocument(new StringReader(xpathStg));
XPathNavigator nav = docNav.CreateNavigator();
XPathNodeIterator NodeIter = nav.Select("/bookstore/book[last()]");
Console.WriteLine("NodeIter.Current.Value=" + NodeIter.Current.Value);