熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#高級編程:使用XPath命名空間中的類[2]

2022-06-13   來源: .NET編程 
    ——此文章摘自《C#高級編程(第版)》定價元 特價元 購買


圖 

    如果要把這些書的成本相加該怎麼辦?XPathNavigator為此包含了Evaluate方法Evaluate有個重載方法第一個包含一個字符串該字符串就是XPath函數調用第二個Evaluate重載方法的參數是XPathExpression對象第三個Evaluate重載方法的參數是XPathExpression 和 XPathNodeIterator如果對示例進行下述修改(這個版本的代碼在XPathXSLSample中)
    private void button_Click(object sender SystemEventArgs e)
    {
       //modify to match your path structure
       XPathDocument doc = new XPathDocument(\\\\\\booksxpathXML);
       //create the XPath navigator
       XPathNavigator nav = docCreateNavigator();
       //create the XPathNodeIterator of book nodes
       // that have genre attribute value of novel
       XPathNodeIterator iter = navSelect(/bookstore/book[@genre=novel]);
       while(iterMoveNext())
       {
          LoadBook(iterCurrentClone());
       }
       //add a break line and calculate the sum
       listBoxItemsAdd(========================);
       listBoxItemsAdd(Total Cost =
                  + navEvaluate(sum(/bookstore/book[@genre=novel]/price)));
    }

    這次可以看到列表框中書籍的總成本如圖所示


圖 

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/14663.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.