• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

is there any other tech to replace XPATH+DOM?

 
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post
For some times we used Xpath and dom parser to find node and attribute (values) in our XML documents, now we fin out that it become a hot spot in our application and this use of XPATH and DOM is using fair amount of cpu times.

is there any other tech to replace this two with them?
we just need to read and pars xml, find node and attributes (values) we do not create XML .

thanks
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried using a SAX parser instead? It may be faster, even though it may possibly involve more code to write, depending on how complex the logic to access particular nodes is.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although XPath is convenient, it is certainly not fast as I found out preparing this article.

Directly coding access using the DOM methods will be a LOT faster since you know exactly what you want.

If all you want is the attributes from a known Element and don't need details about the XML document hierarchy, SAX will be even faster as Ulf suggested.

Bill
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are situations where you look for a particular value (may be an attribute or text in a element).The XML is very big , in that case using SAX is better , but Stax is better suited for this situation.

Consider the following situation.Where are you looking for value of a particular element and that element may appear anywhere in the XML document.

The main disadvantage of using SAX in this case would be , even if you find the element in the beginning of the XML , then also the complete file would be parsed as the parser is in control and would only return when parsing is complete.

In such cases Stax would be more useful because as soon as you find the required node you can stop the parsing process.So it would not parse the entire document.
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post
as some examples of our usage i can mention:
-find all node in the documents that have attribute a='some value'
-find the attribute value which its name is.
-find all nodes, with the name of attribute.

we usually work with small sized xml file (smaller than 10K), does stax or perform better for such condition?

thanks
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by raminaa niilian:

we usually work with small sized xml file (smaller than 10K), does stax or perform better for such condition?



DOM would be better suited for this situation.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The main disadvantage of using SAX in this case would be , even if you find the element in the beginning of the XML , then also the complete file would be parsed as the parser is in control and would only return when parsing is complete.



Not true - all you have to do is throw an exception after the data has been found. Of course you will have to provide for catching the exception properly, but that is no big deal.

Bill
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
Not true


I thought its bad design to control the flow of the program using exceptions.
Well there is nothing wrong in using exception for this purpose.

Is there is disadvantage of using STAX for this issue ?
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is there is disadvantage of using STAX for this issue ?



Actually StAX should be perfect for this application since it avoids the problem of the separate parsing Thread. However, as I understand it, StAX is not yet part of the standard Java library.

This site summarizes the current state of StAX for Java. There is a download for the current version.

Bill
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
However, as I understand it, StAX is not yet part of the standard Java library.



As of JAXP 1.4 -which is part of Java 6- it is.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response William.

It has been included as part of JAXP 1.4 , which is included in JDK 1.6.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by raminaa niilian:
Hi
Thank you for reading my post
as some examples of our usage i can mention:
-find all node in the documents that have attribute a='some value'
-find the attribute value which its name is.
-find all nodes, with the name of attribute.

we usually work with small sized xml file (smaller than 10K), does stax or perform better for such condition?

thanks



I guess these are perfect situations by using XSLT. Simple, easy, can be controlled/changed from external without code changes.

However, I don't know the performance comparing to other approaches.
reply
    Bookmark Topic Watch Topic
  • New Topic