Solved

Using Xalan-J with JDOM?

Posted on 2006-07-10
4
783 Views
Last Modified: 2013-11-23
JDOM allows you to use XPath but the default XPath processor is Jaxen.  How would I go about using Xalan-J from Apache instead?
0
Comment
Question by:ctangent
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
enachemc earned 250 total points
ID: 17079900
In order to change JAXP(main interfaces regarding XML processing) implementations, you have to set system properties.

System property Setting for javax.xml.transform.TransformerFactory set to org.apache.xalan.processor.TransformerFactoryImpl , will mean that the XML transformer used is that from xalan. You can change in this way the DOM parser, SAX parser, XPath implementation, aso. System variable are usualy set using the "-D" option (-Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl) as a parameter for starting the JVM. In order to set the XPathFactory, you would have to set the corresponding system property (javax.xml.xpath.XPathFactory) to your desired implementation.
0
 

Author Comment

by:ctangent
ID: 17082067

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
0
 
LVL 12

Expert Comment

by:enachemc
ID: 17082213
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.
0
 

Author Comment

by:ctangent
ID: 17082273
enachemc, thank you very much for your help!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now