Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7949445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:00:03+00:00 2026-06-04T02:00:03+00:00

Using: Java 1.5 / JDom 1.1.3 / Jaxen 1.1.1 The test I’ve written was

  • 0

Using: Java 1.5 / JDom 1.1.3 / Jaxen 1.1.1

The test I’ve written was to confirm the belief that using precompiled XPATH in JDOM was faster than iterating through child elements. Instead, what I’ve found is that XPATH is between 4 and 5 times slower than iterating through lists of children, performing string comparisons, and hunting for what I want.

For context, my XPath is something like:

/root/quote/vehicle[@id = 'some vehicle']/coverage[@id = 'some coverage']/code";

And the actual evaluation being timed (in a try/catch block):

String element = path.valueOf(doc).getText();

And the alternative search is:

List<Element> vehicleList = doc.getRootElement()
                                        .getChild("quote")
                                        .getChildren("vehicle");

for(Element vehElement : vehicleList)
    if(vehElement.getAttributeValue("id").equals("some vehicle")){
        List<Element> coverageList = ele.getChildren("coverage");
        for(Element covElement : coverageList){
            if(covElement.getAttributeValue("id").equals("some coverage")){
                element = covElement.getChild("CoverageType").getText();
                break;
            }
        }
    }

Curiously, while the runtime of the method using XPATH is much slower, it is most consistent over 1000 iterations.

The first example completes around .29 ms +- 0.01ms.

The second example completes anywhere between .013ms and .002ms.

Both approach very short running times given a long enough test.

The XPath is, for me, easier to write, however the getChild route seems more flexible but a little verbose. Still that’s a trade I don’t mind making for speed. It is also true that even 100 iterations is incredibly fast, so this may be academic…

Ultimately I’d like to know:

Is there a scenario where JDOM Xpath is faster than the alternative style shown ?

What benefits does JDom XPath (in any version of Java/JDOM) bring ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:00:05+00:00Added an answer on June 4, 2026 at 2:00 am

    There are a few things to note in here…. I have done (I’m a JDOM maintainer) extensive work on JDOM 2.0.1 especially in regards to performance of XPath evaluation. Here are some numbers:

    http://hunterhacker.github.com/jdom/jdom2/performance.html

    Read it from the bottom up.

    Here are some other interesting numbers (compares different JDOM versions with different Java VM’s)

    http://hunterhacker.github.com/jdom/jdom2/performanceJDK.html

    The ‘bottom line’….

    • JDOM 2.x introduces faster iterators. Jaxen is very Iterator intensive, and the performance improvements in JDOM 2.x are significant in this regard….
    • Java 7 is much faster than previous versions in regard to iterator performance too.
    • There is no benefit to ‘compiling’ Jaxen XPaths….
    • even in the best of times though, the ‘native’ method of searching will be faster than the XPath version.

    Your biggest performance boost will come from running with Java7, then upgrading to JDOM 2.x

    Although the ‘custom’ search, if written efficiently, will always be faster than XPath.

    Edit: Also, JDOM 2.x introduces a new API for running XPath queries that you may find easier to work with (although the old API still works too): https://github.com/hunterhacker/jdom/wiki/JDOM2-Feature-XPath-Upgrade

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a process that parses an XML file using JDOM and xpath to
Using Java, how can I test that a URL is contactable, and returns a
Using Java (1.6) I want to split an input string that has components of
Using Java, how can I detect all of the browsers that are installed on
Using java, I am writting a script to anchor link an html bibliography. That
Using java and made a small test server to log incoming user connections. Adding
I want to send an xml document that i have created using jdom api.
Using Java is there anyway to display a custom form/image that behaves similar to
I want to make a kml file from a java code using jdom-1.1.jar library
Since I'm using Java 1.4.2, this means that I cannot use Java's implementation of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.