[jdom-interest] XPath Question?

Olivier Coppel olivier.coppel at akazi.com
Tue Jul 2 00:48:22 PDT 2002


>
> How can I use Xpath in JDOM ?

You can use Jaxen for Jdom.

A short example :

    import org.jaxen.*;
    import org.jaxen.jdom.*;

    ...

    String xpathRequest = "child::process[@name='myprocessname']";

    try {

      XPath xpath = new XPath( query );

      // Perform XPath request. Result is an element
      Element e = (Element) xpath.selectSingleNode( elem );
      return e;
    }
    catch ( JaxenException e ) {

      _trace.error( this, e );
      return null;
    }
    catch ( SAXPathException e ) {

      _trace.error( this, e );
      return null;
    }
  }

This example is quite simple and it doesn't take into account namespace. To
use namesapce, you must manage "context".

> For Example, How can I use Xpath to set a element name?

Not to set but to search for an element ... ?






More information about the jdom-interest mailing list