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.
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.
Joined: Jul 24, 2003
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.
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".
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.
Joined: Jun 26, 2002
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.
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.
Joined: Mar 22, 2005
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.)
Joined: Jul 24, 2003
Hi Ulf & Friends,
Thanks for your valuable suggestion, I am using Apache Digester. :-) with the rule file.