使用多个值作为输入搜索XmlDocument

时间:2015-06-09 19:08:33

标签: xml

我必须从.net

搜索下面给出的XML文档
<?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%']"); 

1 个答案:

答案 0 :(得分:0)

首先,您的XML无效。第一行应为此(注意小写xml):

<?xml version="1.0" encoding="UTF-8"?>

然后,你的XPath必须看起来像这样才能得到你想要的东西:

xmlDoc.SelectNodes("//cricketer[contains(name,'an') or contains(name,'mi')]");