要理解這些類的用法,最好是查看一下迭代books.xml文檔的代碼,確定導航是如何工作的。為了使用這些示例,首先需要添加對System.Xml.Xsl 和 System.Xml.XPath命名空間的引用,如下所示:
using System.Xml.XPath;
using System.Xml.Xsl;
這個示例使用了文件booksxpath.xml,它類似于前面使用的books.xml,但booksxpath.xml添加了兩本書。下面是窗體代碼,這段代碼在XPathXSLSample1文件夾中:
private void button1_Click(object sender, System.EventArgs e)
{
//modify to match your path structure
XPathDocument doc=new XPathDocument("..\\..\\..\\booksxpath.xml");
//create the XPath navigator
XPathNavigator nav=doc.CreateNavigator();
//create the XPathNodeIterator of book nodes
// that have genre attribute value of novel
XPathNodeIterator iter=nav.Select("/bookstore/book[@genre='novel']");
文章來源于領測軟件測試網 http://www.kjueaiud.com/