XPath 根据另一个 XPath 元素查找元素
我有一个 Java AST,我尝试通过 XPath 查找其中的变量。
假设该变量名为“foobar”,我可以使用,
//VariableDeclarator/VariableDeclaratorId[@Image='foobar']
但是如果我不知道文本“foobar”,但想从另一个元素读取它,
//VariableDeclarator/VariableDeclaratorId[@Image=//SynchronizedStatement/Expression/PrimaryExpression/PrimaryPrefix/Name]
“Name”节点在 @Image 中具有信息“foobar”,但是 PrimaryPrefix/Name[@Image]
不起作用。
我必须如何重写条件 //SynchronizedStatement/Expression/PrimaryExpression/PrimaryPrefix/Name
使其与 @Image='foobar'
相同?
谢谢
I have an Java AST and I try to find a variable inside it via XPath.
Lets say the variable is called 'foobar' I could use
//VariableDeclarator/VariableDeclaratorId[@Image='foobar']
but what if I dont know the text 'foobar', but want to read it from another element
//VariableDeclarator/VariableDeclaratorId[@Image=//SynchronizedStatement/Expression/PrimaryExpression/PrimaryPrefix/Name]
the 'Name' node has the information 'foobar' in @Image, but PrimaryPrefix/Name[@Image]
does not work.
How must I rewrite the condition //SynchronizedStatement/Expression/PrimaryExpression/PrimaryPrefix/Name
that it is the same as @Image='foobar'
?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个 XPath:-
Try this XPath:-