There are several ways to deal with xml in Java. Depending on the requierements that are stated, you choose the weapons for your duel. Roughly you can divide the xml libraries that are available in Java in the following groups:
- Dom. Document Object Model.
- Marshalling
- Sax. Simple Api for Xml.
- Stax. Streaming Api for Xml.
- Xslt Extensible Stylesheet Language Transformations
The API's:
1. Dom:
These kind of API's create the full xml into memory and structure it in Java classes. The benefit of this is that all the information contained in the xml document is searchable and available. The downside is that, if there are several, bigger documents, it costs a lot of resources to work with it.
Examples of Dom API's are:
3. Sax. Simple Api for Xml.
A Sax parser does not read the whole dom object into memory but reads as a sequential stream. This makes that the resource usage, compared to the dom parsers is significant less. The downside is, that you can retreive anything back from the top ones you passed it. It is event based.
Examples of Sax parsers:
- Xerces (parses not only Sax)
- Axiom (parses not only Sax)
- Ælfred2, (parses not only Sax)
- Crimson, (bundled into JDK 1.4)
- Oracle's XML Parser for Java v2
- Piccolo
- The System Integration Automation Parser for XML
- XP 0.5
Stax libraries are stuck in the middel of Sax and Dom. It is not designed to push the data from the xml stream to the application, but vica versa. It pulls the required data into the application from the xml stream.
Examples of Stax parsers:
Axiom (parses not only Stax)
woodstox
jax
5. Xslt Extensible Stylesheet Language Transformations
Xslt is a language which can do operations on a existing xml structure, and transform this into a new xml structure. In java this means that the xml file will be parsed by a sax parser like Xerces or Crimson. From here we can use the xslt language combined with xpath queries.
Examples of xslt parsers:
XDK
Conclusion
To work with Java and Xml you need to know want and what your requirements are.
So, research and Have Fun.
Geen opmerkingen:
Een reactie posten