Hi,
I am trying to find out the best possible way to load and parse XML files in Java..I have heard of JAXP, JAXB etc..but is there an industry standard that every only is following?
xstream is very fast and easy to use, but you must know the exact xml structure and create a java class that represents it. I found it more useful for serializing objects on disk than for xml parsing.
With jdom you parse or create a xml document with its childs, elements, etc... so it's a better solution if your xml document doesn't have a fixed structure.
dom and jdom parse the entire xml document in memory, so you can go back and forward thru the xml tree and nodes. (dom is a standard defined by W3C, and jdom is similar but defined more "friendly" with java).
xstream also loads the whole xml into memory, but instead of creating a "generix" xml object (a document with childs, nodes, text, etc...) it creates a java class that you must have defined. It's main goal is to serialize java objects into xml documents.
sax doesn't create the entire xml tree structure in memory, so it can be better for large xml files, using less memory. But you cannot process an element once you've read the next one.
dom, jdom, sax, etc... all have their own parser, and you cannot work with a document parsed by one of the them with the other parsers.
JAXP is not a parser, it's a set of classes that can be implemented in other parsers, so if you're using a JAXP supporting parser, you could change to another parser if it also supports JAXP.
JAXB is "similar" to xstream, it doesn't create a "generic" xml document in memory, it creates a specific java object that represents the xml structure. It uses xml schemas to map the elements of the xml document to attributes in the java class.
So once again, it depends on what you need.
I'm not familiar with all this xml stuff, but I think this can give you a starting point based on your needs.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.