Java API for XML (JAXP) – Introduction

What is Java API for XML (JAXP) JAXP is the Java reference implementation for parsing, transforming, validating and querying XML documents. In other words using the JAXP API you can Parse an XML document using the Document Object Model (DOM) representation of the XML document – JAXP provides the classes that form the DOM Model. … Read more

XStream – XML Transformation

XStream provides a TraxSource (extends SAXSource) that can be used as an input to XSLT transformation. The TraxSource uses a java Object and the corresponding XStream Object. The java object can then be directly converted to XSLT target without actually converting to XML. Lets look at an example package com.studytrails.xml.xstream; import java.util.ArrayList; import javax.xml.transform.Transformer; import … Read more

XStream – Json to Java

XStream can also be used with JSON. XStream provides two drivers : a JsonHierarchicalStreamDriver and a JettisonMappedXmlDriver. The JsonHierarchicalStreamDriver can be used to write a JSON string but cannot deserialize a JSON. JettisonMappedXmlDriver can be used to deserialize a JSON but it introduces an additional dependency. In this example we deserialize a json string into … Read more

XStream – Collection Converters

In the earlier tutorials we saw how to convert a Java object to XML and back, custom converter and basic converters. In this tutorial we look at how XStream converts array and collections from java to xml and vice versa. We will convert the following types : String[] char[] List&ltString&gt java.util.Properties List&ltString&gt Map&ltString, String&gt TreeMap&ltString, … Read more

XStream – Basic Built-in Converters

In the previous tutorials we saw an example of how to convert java object to XML and back. That tutorial also explained the concept of aliases and implicit collection.In the last tutorial we show how to write a custom converter. In this tutorial, lets see some of the basic built in converters of XStream and … Read more

XStream – Custom Converter for BufferedImage

In the previous tutorials we saw an example of how to convert a java object to XML and back. That tutorial also explained the concept of aliases and implicit collection. While serializing a Java object to XML XStream uses custom converters. These converters specify how to create XML from a Java Object or how to … Read more

XStream – Referencing Objects

XStream allows you to store references while converting a java object to XML. Consider a case where you have an Artist Object. The object contains albums that the artist has released, but you also want to store a reference to a ‘similar artist’. People listening to an artist might be interested in listening to a … Read more

XStream – Handling Attributes in XML

In the previous tutorial we saw how to convert Java to XML and back. In this tutorial we look at different ways to handle XML attributes using XStream. However note that the attributes are only safe if you know that the written String values are not affected by the XML parser’s white space normalization. The … Read more

XStream – Java to XML Using Annotation

Convert Java to XML using annotation In the previous tutorials we saw an example of how to create a java object from XML. That tutorial also explained the concept of aliases and implicit collection. In this tutorial we continue with that but use annotation on the java class. The advantage with annotation is that it … Read more

XStream – Java to XML

The Problem Statement In the previous example we saw how to convert a Java Object to XML and back. In this example we look at another example of Java Object to XML Conversion. The example uses an object called a ‘JazzArtist’. This object has a list of ‘Album’ objects besides some other properties. We see … Read more