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 511941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:16:08+00:00 2026-05-13T07:16:08+00:00

Is XPath a better way to read configuration file than DOM and SAX? If

  • 0

Is XPath a better way to read configuration file than DOM and SAX?

If yes,

Why does not log4j uses XPathExpression to read configuration file?

If No,

What method should I choose so that I do not have to modify the code if my configuration file changes?

Update:
@kdgregory

Normally you are aware of the parameter you are seeking in a configuration file (even the complete path to the node). Why not use XPathExpression in that case? Does that makes processing slow as every time background parsing takes place?

  • 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-05-13T07:16:08+00:00Added an answer on May 13, 2026 at 7:16 am

    Why does not log4j uses XPathExpression to read configuration file?

    Partly because XPath wasn’t part of the JDK until 1.5, and Log4J’s XML configuration predates that release.

    But probably more because the Log4J configuration file is a simple hierarchical structure, and it’s easy to traverse such a structure and set configuration options. If you look at the source code for org.apache.log4j.xml.DOMConfigurator, you’ll see a very short dispatch loop that looks at the element name hands it off to an object-specific parser.

    Is XPath a better way to read configuration file than DOM and SAX?

    XPath is not a replacement for DOM and SAX, it’s an additional layer on top of them. Yes, you can pass any InputSource to XPathExpression, and you can create an InputSource from any InputStream, but then the parsing happens behind the scenes. And if you have to execute multiple XPath expressions over the same file, it makes a lot of sense to parse it once into a DOM.

    What method should I choose so that I do not have to modify the code if my configuration file changes?

    Configuration files normally change because your code changes, not the other way around: you add a feature that you want to configure, and then write the code to configure it.

    So, when should XPath be used? Where it has more advantage?

    One good use for XPath is when you need to extract specific pieces out of a file, particularly if the order in which you extract them does not correspond to the file’s document order.


    And finally: I strongly recommend using Apache Digester, or any of a number of Java->XML serialization libraries, rather than explicit XPath.

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

Sidebar

Related Questions

I'm not sure how to explain this, so if there's a better way please
There's probably a better way to do this than what I'd doing, because I'm
I have to make xPath dynamical, based on my request attributes in XSL file
I did not get exactly how to use an or operator within an Xpath.
There may be a better way of doing this and if there is please
I am trying to access a specific element of the Dom using XPath Here
I have being messing about with DOM XPath stuff all day - reading around
Is there a way to define a XPath type query for nested python dictionaries.
I'm using the apache commons configuration XMLConfiguration object with the XPATH expression engine to
Can anyone tell me if there is a better way to search an XML

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.