假设有如下XML文件:
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]<?xml version="1.0" encoding="utf-8" ?>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
<bookstore>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]  
<book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
<title>The Autobiography of Benjamin Franklin</title>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
<author>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]      
<first-name>Benjamin</first-name>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]      
<last-name>Franklin</last-name>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
</author>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
<price>8.99</price>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]  
</book>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]  
<book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
<title>The Confidence Man</title>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
<author>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]      
<first-name>Herman</first-name>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]      
<last-name>Melville</last-name>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
</author>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
<price>11.99</price>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]  
</book>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]  
<book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
<title>The Gorgias</title>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
<author>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]      
<name>Plato</name>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
</author>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]    
<price>9.99</price>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]  
</book>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
</bookstore>
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
   需要求出:
1: 所有书的总价,即sum(price)
2:ISBN="0-201-63361-2"的书的价格,使用XPath可以表达: /bookstore/book[@ISBN="0-201-63361-2"]/price

 简单分析:
XPathNavigator/XPathExpression 是2个很重要的类,顾名思义,XPathNavigator是用来定位的Node上下文的,定位之后,才能求出相对的Xpath值。XPathExpression是表达式
 大家看看代码就清楚了:
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]using System;
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
using System.Collections.Generic;
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
using System.Text;
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
using System.Xml.XPath;
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
using System.Xml;
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
使用XPathNavigator和XPathExpression求出XPath的值,[源代码]
namespace XPathNavigatorSample

源代码:/Files/cleo/XPathNavigator.rar

相关文章:

  • 2021-08-19
  • 2022-12-23
  • 2022-01-19
  • 2022-02-11
  • 2021-10-01
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
猜你喜欢
  • 2021-07-06
  • 2021-07-07
  • 2021-10-24
  • 2022-12-23
  • 2021-10-28
  • 2021-12-21
  • 2021-09-13
相关资源
相似解决方案