C#用xpath查找某节点如何写?

来源:百度知道 编辑:UC知道 时间:2024/06/06 01:50:18
假设知道该节点名及某属性值

你这个问题应该至少把xml的整体的结构写出来,别人才好给你解答的。要知道从根节点一直下来的相对路径才能确定Xpath的写法。

/root/<节点1>/<节点2>//<@属性>

Xpath是功能很强大的,但是也是相对比较复杂的一门技术,最好还是到博客园上面去专门找一些专业的帖子来看一看,下面是一些简单的Xpath语法和一个实例,提供给你参考一下

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd country="USA">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
<cd country="UK">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>9.90</price>
</cd>
<cd country="USA">
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<price>9.90</price>
</cd>
</catalog>

定位节点
XML是树状结构,类似档案系统内数据夹的结构,X