[jdom-interest] questions on using XPath.newInstance() and expr

Mikael Petterson (KI/EAB) mikael.petterson at ericsson.com
Fri Jan 30 02:21:53 PST 2004


I downloaded jdom-9.

I looked at the example (jdom-b9/samples) called:


XPath servletPath = XPath.newInstance("//servlet");

To my questions:

Q1:Is it possible to only create one Instance of XPath and just use different expressions when navigating the xml document. That is:

//Global for the class that use it
public static XPath path;

//First time I create XPath
 path = new XPath.newInstance("<myexpression1>");

//Next time I use it, in same class, I do:

List cars = path.selectNodes(doc,"<myexpression2>");

Q2: How can I add a java String variable to an XPath expression? Example:

    String parent = "John";
    String query = "//Foundation.Core.Class[Foundation.Core.ModelElement.name='"+parent+"']/Foundation.Core.Gene

   How can I make sure that query is interpreted as:




More information about the jdom-interest mailing list