• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which XML Parser should I use?

 
Vijay Kumar
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vijay Kumar
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vijay Kumar
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20983
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer.
 
Mazer Lao Tzu
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf & Friends,

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

Thanks
 
Suhas Bilaye
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic