Solved

Using Xalan-J with JDOM?

Posted on 2006-07-10
4
801 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

615 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