我使用xpath查詢C#中的xml文件。Xpath選擇查詢也相對最高級別的節點在C#
這裏是我的xml文件
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
而且我的C#代碼是
XPathNavigator nav;
XPathDocument docNav;
XPathNodeIterator NodeIter;
String strExpression;
docNav = new XPathDocument(@"C:\\DCU\\XQUE.xml");
nav = docNav.CreateNavigator();
// This expression uses standard XPath syntax.
strExpression = "/bookstore[./book/price>35.00]";
NodeIter = nav.Select(strExpression);
while (NodeIter.MoveNext())
{
Console.WriteLine("{0}", NodeIter.Current.OuterXml);
}
但我想這樣的輸出,
<bookstore>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
我認爲任何與失蹤我xpath查詢行,請帶我出去..
謝謝JLRishe ... – 2013-03-08 19:38:49