【发布时间】:2016-10-03 15:23:03
【问题描述】:
使用我的 c# 应用程序,我需要编写一个 xpath 来检查具有属性 alias 的节点是否具有值 title 或 keywords,其中包含一个字符串值,例如 knowledge 返回一个节点值alias,description。
我的示例 xml 如下。我需要来自 xml 的值 required description
<?xml version="1.0" encoding="UTF-8"?>
<nodes>
<node>
<data alias="title">knowledge is power</data>
<data alias="description">required description</data>
<data alias="keywords">knowledge, power</data>
</node>
<node>
<data alias="title">Another title</data>
<data alias="description">Lorem ipsum dolor sit amet, consectetur adipiscing elit </data>
<data alias="keywords">Lorem, Ipsum</data>
</node>
</nodes>
我正在尝试这些线路,但它似乎不起作用
if (xdoc.SelectNodes("nodes/node/data[(@alias='title' or 'keywords')]/[contains(., 'knowledge')]").Count > 0)
{
// extract the description node value here
}
【问题讨论】: