如何通過XPath提取屬性節點的值?通過XPath提取屬性節點的值
示例XML文件是:
<parents name='Parents'>
<Parent id='1' name='Parent_1'>
<Children name='Children'>
<child name='Child_2' id='2'>child2_Parent_1</child>
<child name='Child_4' id='4'>child4_Parent_1</child>
<child name='Child_1' id='3'>child1_Parent_1</child>
<child name='Child_3' id='1'>child3_Parent_1</child>
</Children>
</Parent>
<Parent id='2' name='Parent_2'>
<Children name='Children'>
<child name='Child_1' id='8'>child1_parent2</child>
<child name='Child_2' id='7'>child2_parent2</child>
<child name='Child_4' id='6'>child4_parent2</child>
<child name='Child_3' id='5'>child3_parent2</child>
</Children>
</Parent>
</parents>
到目前爲止,我有這個XPath字符串:
//Parent[@id='1']/Children/child[@name]
它只返回child
元素,但我想有name
屬性的值。
在我的示例XML文件,這裏是想我的輸出是:
Child_2
Child_4
Child_1
Child_3
[使用XPath獲取屬性](http:// stackoverflow。com/questions/4531995/getting-attribute-using-xpath) – tripleee 2015-12-03 08:53:13