XPath 操作 xml
通过 xpath 查找 xml 内容步骤:
- XPathDocument document = new XPathDocument(xmlFullpath); //读取xml内容
- XPathNavigator navigator = document.CreateNavigator(); //创建xml导航器
- XPathExpression expression = navigator.Compile(xpathString); // 将输入的 xpathString, 编译成表达式
- XPathNodeIterator nodeIterator = navigator.Select(expression); //获取节点集
//对节点集迭代器进行遍历:
while (nodeIterator.MoveNext()) {
XPathNavigator node = nodeIterator.Current;
//操作代码....
}