Solved

Using Xalan-J with JDOM?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
for i loop in grovy 1 45
Arrays.asList  VS  ArrayList 4 45
javap not working 8 37
Opening PDF on button click and fill new document 2 19
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This video teaches viewers about errors in exception handling.
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.

920 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

15 Experts available now in Live!

Get 1:1 Help Now