//身体/目标/*/目标//身体/目标2/*/目标How would I obtain a node using Xpath that sometimes has irrelevant nodes in between goal nodes.I have xml file typically in the form as following:<body> <target> <goal>Text I want to obtain</goal> </target> <target2> <goal>Second Target I want to obtain</goal> </target2><body>And I need to throw target's goal and target2's goals in separate string.So I got the "Text I want to obtain" using Xpath "//body/target/goal", and got the "Second Target I want to obtain" using Xpath "//body/target2/goal".Very simple.However later I found out that in between target and goal (or target 2 and goal) there could be separate nodes (not known) as following:<body> <target> <annoying> <goal>Text I want to obtain</goal> </annoying> </target> <target2> <noidea> <goal>Second Target I want to obtain</goal> </noidea> </target2><body>I still have to distinguish the two targets so I cannot just accumulate goal with "//goal". What kind of 2 Xpaths wold I need to obtain each text I need to obtain?Thank you very much in advance 解决方案 Use a wildcard between target/target2 and goal://body/target/*/goal//body/target2/*/goal 这篇关于如何在两个目标节点之间形成不相关节点的Xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-11 13:59