我有一個關於將XPath表達式作爲屬性值傳遞的快速問題。 所以我有以下文件:如何通過獲取引用的屬性來查找元素?
<?xml version="1.0"?>
<personnel>
<person id="EMP01" >
<name><family>Lee</family><given>Ho</given></name>
<email>[email protected]</email>
<salary>100000</salary>
<links>
<subordinate>EMP02</subordinate>
<subordinate>EMP03</subordinate>
</links>
</person>
<person id="EMP02">
<name><family>Chan</family><given>Tai Man</given></name>
<email>[email protected]</email>
<salary>20000</salary>
<links>
<manager>EMP01</manager>
<subordinate>EMP04</subordinate>
<subordinate>EMP05</subordinate>
</links>
</person>
<person id="EMP03">
<name><family>Cheung</family><given>Siu Fan</given></name>
<email>[email protected]</email>
<salary>20200</salary>
<links>
<manager>EMP01</manager>
<subordinate>EMP07</subordinate>
</links>
</person>
<person id="EMP04">
<name><family>Ng</family><given>Ho</given></name>
<email>[email protected]</email>
<salary>11000</salary>
<links>
<manager>EMP02</manager>
</links>
</person>
<person id="EMP05">
<name><family>Chow</family><given>Sing Sing</given></name>
<email>[email protected]</email>
<salary>20050</salary>
<links>
<manager>EMP02</manager>
<subordinate>EMP06</subordinate>
</links>
</person>
<person id="EMP06">
<name><family>Law</family><given>Lai</given></name>
<email>[email protected]</email>
<salary>5050</salary>
<links>
<manager>EMP05</manager>
</links>
</person>
<person id="EMP07">
<name><family>Chan</family><given>Siu Ming</given></name>
<email>[email protected]</email>
<salary>5000</salary>
<links>
<manager>EMP03</manager>
</links>
</person>
我需要一個XPath表達式得到家人名爲法的經理人節點,所以在這種情況下,周先生。但是,如何在不明確使用名稱Chow的情況下在XPath中獲得此信息?
我的嘗試是:
personnel/person[@id="personnel/person/name/family='Law'"]
但它並沒有真正的工作......我可以通過一個XPath的值這樣的屬性,或者我該怎麼辦呢?
您可以附加'/文()',如果你是在內容只是感興趣。 – ceving
啊....好的,我認爲屬性的值總是要加引號^^很酷,謝謝你! –