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.
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.
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.
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.
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.
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.