Domanda

So I'm reading from an XML file with many layers of nesting in Java using xPath.

At the moment I have a method that takes the path to XML file and a xpath query as parameters, and returns a NodeIterator.

Then I iterate through those node, and for some of the nodes (if their name matches) I need to execute another query on them and get a NodeIterator of their children etc

Is it possible to have a function with 2 parameters, one an already existing Node and the other an xPath query to execute on that Node?

So replacing:NodeIterator ni = XPathAPI.selectNodeIterator(document,xpathQuery); With some like : NodeIterator ni2 = xPathAPI.selectNodeIterator(parentNode, query);

I've searched on the internet and I can't find any examples, and I'm not sure what the syntax to do the above would be, or if it's even possible?

Many thanks in advance :)

È stato utile?

Soluzione

Presumably your XPathAPI class is the Apache/Xalan org.apache.xpath.XPathAPI?

In that case, what's wrong with

static NodeIterator selectNodeIterator(Node contextNode, java.lang.String str) 

It seems to do exactly what you want.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top