aspose file tools*
The moose likes Performance and the fly likes Which XML Parser should I use? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Which XML Parser should I use?" Watch "Which XML Parser should I use?" New topic
Author

Which XML Parser should I use?

Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
Hi Friends,

I am developing some API for my project for which, I need to load a configuration file.

Please let me what is the best way load the XML base configuration files. Although I found various way to do it like JAXB, Apache commons configurations digester etc but need some review from your side.

Thanks
Vijay Kumar
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
Config files generally aren't all that big; are you really worried about performance? I'm asking because that's what this forum is all about.


Ping & DNS - my free Android networking tools app
Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
Hi Ulf thanks for the reply.

I have gone through with various API(s). like JAXB, Digester etc.

I am looking for easy to use and quit good performance.

If I use Digester then I need to maintain the rule file or need to supply XPATH and beans but in case of JAXB need to call only unmarshaller method and easy to use also JAXB auto generate all required java data structure i.e beans.

Regards,
Vijay Kumar
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
I can't imagine any application where loading a configuration file would be a bottle neck. I would go with the tool that fits your nonperformance needs the most.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
Hi guys,
Thanks for your reply.

I think I should ask question like this.

Which XML parser should I use to load XML configuration?

Like if I have a small xml configuration file and I have a memory constraint then which parser should I use?

Regards,
Vijay Kumar
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18655
    
    8

If you don't have enough memory to use an XML parser to parse a small XML document, then you aren't going to have enough memory to do anything useful. Really, the answer (as everybody is saying here) is "Use whatever parser is the most convenient".
Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
Thanks for your answer.
Mazer Lao Tzu
Ranch Hand

Joined: Jan 20, 2010
Posts: 35
Is this a really large configuration file? In the typical case, your configuration memory usage should never be the problem. If it is, using Java and XML might not be the best solution.

However, DOM parsers will typically take up more memory than SAX parsers when reading XML.



-- Mazer
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
How big are your configuration files? How many? How often must they be read? Are they of a simple format like key, value pairs (i.e. a logical hashmap) or something more complicated? If the answers to these questions are that you have a few small key/value xml files that are loaded at startups then this really isn't a performance question. Either way knowing this type of information will allow people better help you.
raghu mrvreddy
Greenhorn

Joined: Nov 24, 2006
Posts: 7
As far as I know SAX parser is best suited for loading configuration files. DOM would create a object-oriented hierarchical representation of the xml file which we generally doesn't need for configuration files.

Sax parser is generally used for configuration file loading in most of the frameworks.

Even for key value pair, SAX would be the better option.

However depending on your requirements, check the advantages of SAX and DOM, pick the best suited one.

Raghu
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
As far as I know SAX parser is best suited for loading configuration files.

Make sure to check out Apache Digester, it makes such tasks much pleasanter to deal with. (A bit off topic, since Digester uses a parser underneath.)
Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
Hi Ulf & Friends,

Thanks for your valuable suggestion, I am using Apache Digester. :-) with the rule file.

Thanks
Suhas Bilaye
Ranch Hand

Joined: Sep 10, 2009
Posts: 80
Hi Vijay,

I just thought of posting this link where various methods of parsing xml files are shown with their respective drawbacks.
It might help you make a decision.

http://www.javazoom.net/services/newsletter/xmlgeneration.html

Regards,
Suhas


Thanks and Regards,
Suhas
http://www.xplore-java.blogspot.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which XML Parser should I use?