GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes XPath Technology Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPath Technology" Watch "XPath Technology" New topic
Author

XPath Technology

Jose Mon
Ranch Hand

Joined: Feb 13, 2007
Posts: 30
Hi,
If I am using XPath for selecting nodes from Xml, what kind of parsers is used internally. SAX technique or DOM, or this uses a different technology for finding nodes and elements of Xml?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
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.

Bill
Jose Mon
Ranch Hand

Joined: Feb 13, 2007
Posts: 30
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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
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.

Bill
 
GeeCON Prague 2014
 
subject: XPath Technology