Xpath query from a specific node

smartguy911_911

New Member
The usual queries that I'm currently supporting are from the root , meaning : \[code\]public Object evaluate(String expression, QName returnType) {...}\[/code\]Now I want to do the Xpath query starting from some given Node , e.g. :\[code\]public Object evaluate(String expression, Node source, QName returnType) { ? } \[/code\]Then , If my usual queries look like this (here's an exmaple) : \[code\]//load the document into a DOM DocumentDocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();domFactory.setNamespaceAware(true); // never forget this!DocumentBuilder builder = domFactory.newDocumentBuilder();Document doc = builder.parse("books.xml");//create an XPath factoryXPathFactory factory = XPathFactory.newInstance();//create an XPath ObjectXPath xpath = factory.newXPath();//make the XPath object compile the XPath expressionXPathExpression expr = xpath.compile("/inventory/book[3]/preceding-sibling::book[1]");//evaluate the XPath expressionObject result = expr.evaluate(doc, XPathConstants.NODESET);NodeList nodes = (NodeList) result;//print the outputSystem.out.println("1st option:");for (int i = 0; i < nodes.getLength(); i++) { System.out.println("i: " + i); System.out.println("*******"); System.out.println(nodeToString(nodes.item(i))); System.out.println("*******");\[/code\]What kind of changes would I need for making this happen for the above method (\[code\]public Object evaluate(String expression, Node source, QName returnType);\[/code\]) Thanks!
 
Back
Top