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