我正在寻找正确的xpath语法来获取元素的特定父级.例:
root
|- div
| |
| |----??? ---|
| | |-a [class=1]
| | |- text[ A TEXT I DON'T WANT]
| |
| |
| |
| |-text[THE TEXT]
|
|-div
| |-text[THE TEXT I DON'T WANT]
|
|-div
| |-text[THE TEXT I DON'T WANT]
Run Code Online (Sandbox Code Playgroud)
我希望得到文本"THE TEXT",但是包含a [class=1]在同一个div中的文本.像这样的东西:
//div//a[@class=1]/text[contains(.,'A TEXT')]/parent::*/parent::*.... <till div element> /text
Run Code Online (Sandbox Code Playgroud) 我有以下xml.我需要使用xpath查询获取根节点的所有子节点.我怎么写xpath表达式?
<rootElement>
<rootElementOne xmlns="http://some.com">
<rootElementTwo>
<Id>12345</balId>
<name>Name1</businessName>
</rootElementTwo>
</rootElementOne>
<rootElementOne xmlns="http://some.com">
<rootElementTwo>
<Id>6789</balId>
<name>Name2</businessName>
</rootElementTwo>
</rootElementOne>
</rootElement>
Run Code Online (Sandbox Code Playgroud)
表达式应返回以下结果:
<rootElementOne xmlns="http://some.com">
<rootElementTwo>
<Id>12345</balId>
<name>Name1</businessName>
</rootElementTwo>
</rootElementOne>
<rootElementOne xmlns="http://some.com">
<rootElementTwo>
<Id>6789</balId>
<name>Name2</businessName>
</rootElementTwo>
</rootElementOne>
Run Code Online (Sandbox Code Playgroud)
我尝试使用rootElement/rootElementOne/*但没有结果.
谢谢!