Xml xpath获取类别值为“0”的任何小工具;旅游业;,以及gadget之前的任何兄弟姐妹[1]
我有一个xml结构的表单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
<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]