【发布时间】:2014-01-11 13:24:23
【问题描述】:
我在根目录下直接有这样的xml节点,
<online.png>
<createdBy>admin</createdBy>
<mimeType>image/png</mimeType> // may be here in node itself
<primaryType>nt:file</primaryType>
<content>
<firstName>Vendor</firstName>
<mimeType>image/png</mimeType> // may be here in child
<city>Hyderabad</city>
</content>
</online.png>
从这个节点,如何使用 xpath 获取顶部父节点(这里是 gif 图像节点),而不管 mimetype 位置如何,我还想首先根据其值获取节点名称,如搜索。即,
stirng xpath = select top-paren where element name has value ('image/')
/ -- "//*[contains(text(),'image/')] select top parent"
欢迎提出任何建议。
XmlNodeList nodeImages = xmlDoc.SelectNodes("//*[contains(text(),'image/')]");
返回内容节点和 gif 节点。我只想要gif节点
【问题讨论】:
-
我在你的 xml 中搜索了
gif并没有找到任何东西 -
对不起,这是 png 不是 gif
-
您要选择
<online.png>元素吗?