这是我的文档结构
for key in diff:
if key in first:
print 'First IP'
elif key in second:
print 'Second IP'
我想选择<item_name>Item 1</item_name>
<item_description>Item 1 Description</item_description>
<item_name>Item 2</item_name>
<item_description>Item 2 Description</item_description>
...
... More <item_*> elements
<item_name>Item 400</item_name>
<item_description>Item 3 Description</item_description>
<item_name>Item 401</item_name>
<item_description>Item 4 Description</item_description>
...
... More <item_*> elements
元素作为text()
答案 0 :(得分:1)
使用following-sibling
轴。例如,假设每个item_name
后跟item_description
元素:
//item_name[.='Item 400' or .='Item 401']/following-sibling::item_description[1]/text()
或者如果某些item_name
可能没有相应的item_description
,并且您希望在这种情况下不返回任何内容:
//item_name[.='Item 400' or .='Item 401']
/following-sibling::*[1][self::item_description]
/text()