Solved

Using Xalan-J with JDOM?

Posted on 2006-07-10
4
792 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 77
Opening PDF on button click and fill new document 2 47
web application structure 18 103
restrict decimal places for double datatype 10 22
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

820 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