JAXB Rating

I have a couple of questions about JAXB :

  • What are the options for parsing? Can I easily implement / connect my own parser?

  • How about reality? Suppose I have a relaxed parser that is somewhat relaxed with respect to the schema. Can I create an (invalid) object structure?

  • Does JAXB provide special tools for execution, for example. validation of objects? I would like to analyze the structure of "invalid" objects, execute some algorithms, and then check (in Java).

  • Does JAXB provide other tools for creating interesting objects on objects (for example, a visitor template).

  • What about the amount of memory? Is object representation (excluding parsing) possible for XML files of 10-100 MB in size?

Good tutorials dealing with such issues are appreciated; Google has revealed only rude reviews.

+4
source share
1 answer

Below are my answers to your questions:

What are the options for parsing? Can I implement / connect my own parser easily?

JAXB ( JSR-222 ), the implementation can be disconnected from many different types of input: InputStream , InputSource', Node , XMLStreamReader , XMLEventReader , File , Source`. If your XML representation matches any of them, then you are all set.

How about reality? Suppose I have a relaxed parser that is somewhat relaxed with respect to the scheme. Can I create a (invalid) Structure Object?

JAXB implementations require XML to be well-formed, but do not require it to be valid with respect to the XML schema. It is designed to handle a wide range of documents. If you want to provide "validity", you can install an XML schema (see JAXB and the Unmarshal Schema Validation ).

Does JAXB provide special tools for execution, for example. validation of objects? I would like to analyze the structure of "invalid" objects, the algorithm to fix it, and then check (in Java).

You can use the javax.xml.validation APIs to validate against the object model. Full example:

Does JAXB provide other ways to do things on 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:

What about the amount of memory? Is an object representation (excluding parsing) acceptable for 10-100 MB XML files?

Yes, JAXB can be used to process documents of this size. If you are worried about size, you can use the XMLStreamReader to parse the XML file, and then disconnect the objects from the XMLStreamReader in pieces.

+3
source

Source: https://habr.com/ru/post/1416405/


All Articles