XPath 操作 xml

 

通过 xpath 查找 xml 内容步骤:

  1. XPathDocument document = new XPathDocument(xmlFullpath); //读取xml内容
  2. XPathNavigator navigator = document.CreateNavigator(); //创建xml导航器
  3. XPathExpression expression =  navigator.Compile(xpathString); // 将输入的 xpathString, 编译成表达式
  4. XPathNodeIterator nodeIterator = navigator.Select(expression); //获取节点集

 

//对节点集迭代器进行遍历:

while (nodeIterator.MoveNext()) {
     

      XPathNavigator node = nodeIterator.Current;

      //操作代码....

}

posted @ 2012-11-10 17:05  Yu  阅读(149)  评论(0编辑  收藏  举报