Evaluating JAXB
java, jaxb, xml
Solution
Below are my answers to your questions:
What options are there for parsing? Can I implement / plugin my own parser easily?
JAXB (JSR-222) implementations can unmarshal from many different input types: `InputStream`, `InputSource',`Node`,`XMLStreamReader`,`XMLEventReader`,`File`,`Source`. If your XML representation matches any of these then you're all set.
What about validity? Suppose I have a relaxed parser that is somewhat relaxed regarding the schema. Can I still create an (invalid) object-structure?
JAXB implementations requires that the XML be well formed, but does not require it be valid against an XML schema. It is designed to handle a wide range of documents. If you want to ensure "validity" then you can set an XML schema (see JAXB and Marshal/Unmarshal Schema Validation).
Does JAXB provide special means to do e.g. validation on the objects? I'd like to parse to an "invalid" object structure, have some algorithm repair it, then validate (in Java).
You can use the `javax.xml.validation` APIs to do validation on an object model. For a full example see:
- http://blog.bdoughan.com/2010/11/validate-jaxb-object-model-with-xml.html
Does JAXB provide other means to do fancy things on the objects (e.g. visitor pattern).
JAXB models are POJOs so you can design them as you wish. You may be interested in the following classes:
- http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/Marshaller.Listener.html
- http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/Unmarshaller.Listener.html
What about the memory footprint? Is the object representation (disregarding the parsing) feasible for XML files of 10-100MB?
Yes JAXB can be used to process documents of that size. If you are concerned about size, you can use an `XMLStreamReader` to parse the XML file and then unmarshal objects from the `XMLStreamReader` in chunks.
Problem
I have a couple of questions about `JAXB`: What options are there for parsing? Can I implement / plugin my own parser easily? What about validity? Suppose I have a relaxed parser that is somewhat relaxed regarding the schema. Can I still create an (invalid) object-structure? Does `JAXB` provide special means to do e.g. validation on the objects? I'd like to parse to an "invalid" object structure, have some algorithm repair it, then validate (in Java). Does `JAXB` provide other means to do fancy things on the objects (e.g. visitor pattern). What about the memory footprint? Is the object representation (disregarding the parsing) feasible for `XML` files of 10-100MB? Good tutorials covering this kind of questions are appreciated, Google revealed only coarse overviews.