Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using Xalan-J with JDOM?

Posted on 2006-07-10
4
Medium Priority
?
812 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 1000 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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

972 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