Link to home
Start Free TrialLog in
Avatar of ctangent
ctangent

asked on

Using Xalan-J with JDOM?

JDOM allows you to use XPath but the default XPath processor is Jaxen.  How would I go about using Xalan-J from Apache instead?
ASKER CERTIFIED SOLUTION
Avatar of enachemc
enachemc
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ctangent
ctangent

ASKER


In the class org.jdom.xpath.XPath, there is a function:

static void       setXPathClass(java.lang.Class aClass)
          Sets the concrete XPath subclass to use when allocating XPath instances.

from: http://www.jdom.org/docs/apidocs/org/jdom/xpath/XPath.html


I want to clarify, what I would like to do is use xpath calls with JDOM, so that:

for XML doc:

<appxml>
  <function name="test">1</function>
  <function name="foo">2</function>
</appxml>

Instead of doing:

List funcs = root.getChildren("function");
Iterator i = funcs.iterator();

Element fooFunc;
while(i.hasNext()){
  Element e = (Element) i.next();
  if(e.getAttributeValue("name").equals("foo"))
    fooFunc = e;
}

I can do:
Element fooFunc = (Element) XPath.selectSingleNode(this.root,"function[@name='foo']");



From this clarification, does your suggestion still stand?  Should I ignore the JDOM XPath function setXPathClass(java.lang.Class aClass)
JDOM defaults to using Jaxen as it's XPath parser, which is not good if I want to use Xalan-J
My suggestion reffers only to the XPath implementation. The results should be the SAME ON ANY IMPLEMENTATION. If this is not the case, then it means that particular implementation does not respect W3C. My suggestion still stands (you should select the XPath implementation using A JVM system property).

Your code snippet seems correct.
enachemc, thank you very much for your help!