Suppose I have the following XPath expression: /[EMAIL PROTECTED]
When I evaluate the expression e.g.
String exp="/[EMAIL PROTECTED]";
NodeList nodeList=(NodeList)xpath.evaluate(exp,domDoc,
XPathConstants.NODESET));
I notice that my resolveVariable method is called for each result. Now,
the behaviour I want is for the resolveVariable method to be called once
for each invocation of xpath.evaluate(). The idea being, that I can then
extract a section of a document based on its section_id which I provide
through variable resolution.
I guess I would call this Lazy resolution? Is there a way to do this using
an Java XPath implementations?
//For illustrative purposes only.
public Object resolveVariable(QName var){
//List uniqueIDs declared elsewhere.
System.out.println("Resolver invoked");
if (var.equals(new QName("section_id"))){
Integer uniqueID=-1;
if(uniqueIDs.hasNext()){
uniqueID=Integer.valueOf(uniqueIDs.next().toString());
}
return uniqueID;
}else{
return null;
}
}
}
Thanks,
A.