我有一個 XML 檔案,我需要為其提取一些文本,并且我正在嘗試定義一個 xpath 運算式,該運算式將根據祖先/兄弟節點的值找到該元素。
舉個例子更容易......在下面的 XML 中,對于每個節點,只有當元素的文本值為“正”<feature>時,我才想獲取元素的值:<content><name>
<root>
<feature id="1c4">
<head>
<name>positive</name>
</head>
<values>
<value id="qwqwq">
<content>Content-yes</content>
</value>
</values>
</feature>
<feature id="1c5">
<head>
<name>negative</name>
</head>
<values>
<value id="wtrwt">
<content>Target-no</content>
</value>
</values>
</feature>
</root>
我可以很容易地找到所有元素(包括我不想要的元素)://root/feature/values/value/content
<name>如果內容值為“正” ,我可以找到元素://root/feature/head/name[text() = "positive"]
但是我怎樣才能將兩者結合起來找到//root/feature/values/value/contentONLY when//root/feature/head/name[text() = "positive"]為真時的值?
我試圖在<feature>節點級別組合運算式,但這似乎不是一個有效的 xpath 運算式://root/feature[/head/name[text() = "positive" and /values/value/content]
在此先感謝您的幫助!
F
uj5u.com熱心網友回復:
嘗試這個...
/root/feature[head/name='positive']/values/value/content
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/444242.html
