Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml xpath获取类别值为“0”的任何小工具;旅游业;,以及gadget之前的任何兄弟姐妹[1]_Xml_Xpath - Fatal编程技术网

Xml xpath获取类别值为“0”的任何小工具;旅游业;,以及gadget之前的任何兄弟姐妹[1]

Xml xpath获取类别值为“0”的任何小工具;旅游业;,以及gadget之前的任何兄弟姐妹[1],xml,xpath,Xml,Xpath,我有一个xml结构的表单 <Gadgets> <!--This is the root node--> <info> <author>Yours sincerely</author> <email>me@yahoo.com</email> <phone&g

我有一个xml结构的表单

<Gadgets>              <!--This is the root node-->                          

<info>                
    <author>Yours sincerely</author>
    <email>me@yahoo.com</email>         
    <phone>+23407------</phone>
    <website>me.com</website>
</info>

<!-- I want info and any node before here selected--> 

<gadget>
    -------
</gadget>   

<gadget>
    <title>News</title>
    <link>blalblala.php</link>
    <description>contains News</description>
    <category>Tourism</category>
    <image url="image2.jpj" title="image name" link="location.jpg"/>
    <comment>link to image comments</comment>
    <enclosure url="blaaaa.jpg" length="something" type="imag"/>
</gadget>

<gadget>
我也试过:

"./*/gadget[category = 'Tourism' or following-sibling::gadget[1]]"

“Gadgets/*[self::gadget and category='Tourism'或(self::following sibling::gadget)]”

没有人按预期选择信息。任何导游都将不胜感激。谢谢

试试这个:

//gadget[./category/text()='Tourism'] | //gadget[1]/preceding-sibling::*
或者,如果您只需要一个最靠近第一个
小工具的“任意节点”,请使用

//gadget[./category/text()='Tourism'] | //gadget[1]/preceding-sibling::*[1]
//gadget[./category/text()='Tourism'] | //gadget[1]/preceding-sibling::*[1]