This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
XPath searches a document. That's all. In theory it doesn't matter what kind of parser was used, but typically it searches a tree structure (a "DOM") that has already been built by a parser rather than searching and parsing at the same time.
And typically these DOM objects are built by something that uses a SAX parser to break a document into its constituent parts, but that isn't important. What is mostly important is the abstractions (such as DOM and XPath) that you use to work with XML documents.
The great virtue of XPath is clarity of expression, but this comes at a cost in execution time so if you have a LOT of operations to perform in a DOM you may want to look into working closer to the org.w3c.dom package methods. I made some test timings for this article.
Joined: Feb 13, 2007
Hi, My xml sometimes contains 20,000 to 25,000 lines. In this context is Xpath is preferable. Will it cause any performance problems? Anyway using XPath make coding much easy.
Author and all-around good cowpoke
Joined: Mar 22, 2000
Will it cause any performance problems?
XPath will certainly be much slower than direct use of the more primitive methods. It is only to be expected since XPath has to use those methods to get to XML nodes anyway.
It is up to you to decide if the clarity of code is worth the slower response.