XOM 中的查询节点
我正在 XOM 中查询文档,获取一个节点,然后在该节点中查询另一个节点。然而,查询 Node 的行为就像查询整个文档,而不仅仅是这个节点。
XML 是这样的:
<root>
<someotherstuff>
<DifferentNode>
<Value1>different-value1</Value1>
</DifferentNode>
<Node>
<Node>
<Value1>value1</Value1>
<Value2>value2</Value2>
</Node>
<Node>
<Value1>value3</Value1>
<Value2>value4</Value2>
</Node>
<!-- more Node's -->
</Node>
</someotherstuff>
</root>
我正在这样做:
Nodes nodes = document.query("//Node/Node", X_PATH_CONTEXT);
Node node = nodes.get(0);
Nodes innerNodes = node.query("/Value1");
并且 innerNodes
包含 0 个子节点。当我将 "/Value1"
更改为 "//Value1"
(添加了斜杠)时,我得到了 different-value1,所以看起来它正在查询整个文档,而不是我选择的节点。
如何查询XOM中的特定节点?
I am querying document in XOM, getting a Node, and then querying this Node for another Node. However, querying Node behaves like it's querying whole document, not only this node.
XML is like this:
<root>
<someotherstuff>
<DifferentNode>
<Value1>different-value1</Value1>
</DifferentNode>
<Node>
<Node>
<Value1>value1</Value1>
<Value2>value2</Value2>
</Node>
<Node>
<Value1>value3</Value1>
<Value2>value4</Value2>
</Node>
<!-- more Node's -->
</Node>
</someotherstuff>
</root>
And I'm doing this:
Nodes nodes = document.query("//Node/Node", X_PATH_CONTEXT);
Node node = nodes.get(0);
Nodes innerNodes = node.query("/Value1");
And innerNodes
contains 0 children. When I change "/Value1"
to "//Value1"
(slash added) then I'm getting different-value1, so it looks like it's querying whole document, instead of my selected Node.
How can I query specific Node in XOM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您的查询以单个斜杠开头时,它将查找具有给定名称的文档根节点。两个斜杠相反意味着查找给定名称的所有祖先。如果您只是省略前导斜杠,您的查询应该可以工作:
When your query starts with a single slash then this looks for the document root node with the given name. Two slashes in contrast means to look for all ancestors of the given name. Your query should work if you simply omit the leading slash: