Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Java and XML - Part 1

DZone's Guide to

Java and XML - Part 1

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

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) 
For better understanding of the three interfaces and methods I can recommend you read the DZone Refcard (requires registration) on  Using XML with Java ,or this  useful article  where all 3 interfaces are described very well.
  
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.

Oracle Links:


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.

Oracle Links:

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}