Java and XML - Part 1
Java and XML - Part 1
Join the DZone community and get the full member experience.Join For Free
Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.
This is another article about Java and XML in general with some links to other articles. Also I added some terms to explanation what all the abbreviation stands for.
For all readers which do not know what Java and XML is here are some wikipedia links:
When using Java as programming language in your application you will sometimes be confronted with the need to work with XML, such parsing or writing data. For those purposes there are two Java APIs available: JAXP and JAXB
JAXP - Java API for XML Processing
The API which is used to manipulate XML files via Java is called Java API for XML Processing ( JAXP ).
There are three different processing methods for manipulating the XML files via JAXP:
- DOM (Document Object Model)
- SAX (Simple API for XML)
- StAX (Streaming API for XML)
From the implementation description from the given sources above you can see that the SAX method of parsing is the most boxed, and I think the least used method for manipulating XML via Java. (Correct me if I am wrong.)
Several weeks ago, I saw that J2EE 7 has a JSON API with a DOM-like implementation, where JSON Objects are used, and the StAX method, where an iterator iterate through the JSON Stream/File. Maybe that is some kind of proof that the SAX parsing method is the most unused method and as such, wasn't implemented for the manipulation of JSON files.
Besides these three implementations in Java SE there are others XML parsers which are not part of the Java core API.
Next Step / Article: I would like to write something about the JDOM2 and the W3C DOM parser. Also the usage of XPath will take a part in the explanation of the parser descriptions.
Next Step / Article: XSLT will be another theme that should be mentioned here.
JAXB - Java Architecture for XML Binding
Other way to read the data from XML file or to write Java data to a XML file is to bind them to Java object via the JAXB API.
The main two terms used for this kind of processing are:
- Marshalling - the process when data from Java objects are written into XML.
- Unmarshalling - the process when XML data is transformed into Java objects.
Next Step / Article: In an extra article I will write about JAXB usage, including the most used annotations and adding some links where I have got my information from.
Opinions expressed by DZone contributors are their own.