我必须从.net
<?XML version="1.0" encoding="UTF-8"?>
<cricketers>
<cricketer type="lefty">
<name>Shikhar Dhawan</name>
<role>Batsman</role>
<position>Point</position>
</cricketer>
<cricketer type="righty">
<name>Virat Kohli</name>
<role>Batsman</role>
<position>cover</position>
</cricketer>
<cricketer type="righty">
<name>Shami</name>
<role>Bowler</role>
<position>SquareLeg</position>
</cricketer>
<cricketer type="lefty">
<name>Zaheer Khan</name>
<role>Bowler</role>
<position>FineLeg</position>
</cricketer>
</cricketers>
我想选择所有cricketer
个节点,其名称包含&#39; 或&#39; mi&#39;
这是我试过的xpath语句:
XmlNodeList BasicNodeList = xmlDoc.SelectNodes("cricketer[name='%an' and name='%mi%']");
答案 0 :(得分:0)
首先,您的XML无效。第一行应为此(注意小写xml
):
<?xml version="1.0" encoding="UTF-8"?>
然后,你的XPath必须看起来像这样才能得到你想要的东西:
xmlDoc.SelectNodes("//cricketer[contains(name,'an') or contains(name,'mi')]");