教程

https://www.w3schools.com/xml/xpath_nodes.asp

节点之间的关系

Parent,Children,Siblings,Ancestors,Descendants

qutoric

最新的online工具  http://www.qutoric.com/xslt/analyser/xpathtool.html

旧版的 http://qutoric.com/sketchpath/xpath-editor.html

visual studio的插件

https://github.com/uli-weltersbach/XPathTools

https://github.com/uli-weltersbach/XPathTools/wiki 使用方法

Copy value-based XPath

https://github.com/uli-weltersbach/XPathTools/wiki/Copying-XPaths#copy-value-based-xpath

在Distinct XPath中新增一个key,这样可以拿到appSettings下面的key/value的xpath

/configuration/appSettings/add[@key='OutputRuleWebPartExecutionTimeElapse']/@key

<add key="OutputRuleWebPartExecutionTimeElapse" value="False" />

将鼠标放在add上面,右键,选择copy xpath,然后找到第三个

得到的路径 /configuration/appSettings/add[@key='OutputRuleWebPartExecutionTimeElapse']

这个node的OuterXml是:<add key="OutputRuleWebPartExecutionTimeElapse" value="False" />

这个node的value是null

 

将鼠标放在value上面,选择copy xpath,然后找到第三个

得到的路径 /configuration/appSettings/add[@key='OutputRuleWebPartExecutionTimeElapse']/@value

这个node的OuterXml是:value="False"

这个node的value是: False

 [Test]
public void XPathTest()
{
var path1 = "/configuration/appSettings/add[@key='OutputRuleWebPartExecutionTimeElapse']";
var path2 = "/configuration/appSettings/add[@key='OutputRuleWebPartExecutionTimeElapse']/@value"; var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var fileName = "test.xml";
var filePath = Path.Combine(desktopPath, fileName);
var doc = new XmlDocument();
doc.Load(filePath);
var node1 = doc.SelectSingleNode(path1);
var node2= doc.SelectSingleNode(path2);
Console.WriteLine(node1.OuterXml);
Console.WriteLine(node2.OuterXml);
Console.WriteLine(node2.Value);
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="OutputRuleWebPartExecutionTimeElapse" value="False" />
</appSettings>
</configuration>

多种方法,通过C#移除xmlnode

https://stackoverflow.com/questions/6500989/deleting-xml-using-a-selected-xpath-and-a-for-loop

XmlDocument document = new XmlDocument();
document.Load(fileName); XmlNode node = document.SelectSingleNode("Elements/Element1");
node.ParentNode.RemoveChild(node); document.Save(fileName);

Editing XML Data using XPathNavigator

https://docs.microsoft.com/en-us/dotnet/standard/data/xml/editing-xml-data-using-xpathnavigator

https://docs.microsoft.com/en-us/dotnet/api/system.xml.xpath.xpathnavigator.select?view=netframework-4.7.2

最新文章

  1. Python标准模块--Unicode
  2. 如何更新firefox中的flash
  3. shell中for循环总结
  4. IPv6 neighbor discovery
  5. API Hook完全手册
  6. BOM总结
  7. [译]Selenium Python文档:四、元素定位
  8. 审核Memcrashed Drdos攻击代码
  9. log4cxx用环境变量设置输出文件名
  10. Objective-C点语法
  11. 百度地图DEMO-路线导航,测距,标点
  12. Python2和Python3安装教程
  13. ios开发蓝图
  14. git----------SourceTree如何连接ssh的仓库地址,这里记录的是客户端需要做的事
  15. 洛谷 P3225 [HNOI2012]矿场搭建 解题报告
  16. Java中Dom4j解析XML
  17. Python3基础 dict 推导式 生成10以内+奇数的值为True 偶数为False的字典
  18. MySQL学习(六)
  19. windows7(64位) PHP APACHE MYSQL
  20. 集成学习算法总结----Boosting和Bagging(转)

热门文章

  1. 扩增子分析QIIME2-3数据导出Exporting data
  2. 通过acdbblockreference 获得块名
  3. oracle数据库子查询的结果需要使用多次解决办法
  4. TWaver 3D作品Viewer查看器
  5. 17Aspectij
  6. enote笔记语言(2)(ver0.4)
  7. TestNG套件测试(一)
  8. elasticsearch数据库使用
  9. java连接数据库(经常用)
  10. Linux下汇编语言学习笔记71 ---