amorfis
amorfis

Reputation: 15770

Query Node in 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?

Upvotes: 1

Views: 808

Answers (1)

J&#246;rn Horstmann
J&#246;rn Horstmann

Reputation: 34024

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:

Nodes innerNodes = node.query("Value1");

Upvotes: 4

Related Questions