Java API for XML (JAXP) – XSLT Transformation

XSLT Introduction XSLT is the language for transforming XML documents into other documents such as HTML or other XML documents. It is part of the XSL or XML Schema language. The input to the transformation is a source tree and the output is the result tree. It uses predefined templates to match parts of the … Read more

Java API for XML (JAXP) – Validation

Validating XML using DTD or XSD An XML document is considered ‘well-formed’ if it follows the normal rules of XML. i.e. all tags are closed properly etc. On the other hand, an XML is considered valid if it follows the rules specified in the DTD or XSD. In the example below we look at validating … Read more

Java API for XML (JAXP) – StAX

StAX API in JAXP StAX stands for Streaming API for XML. In the earlier tutorials we have seen DOM (Document Object Model) where a Document tree is created out of the xml and the entire document tree is stored in memory. We have also see the SAX (Simple API for XML) API wherein the parser … Read more

Java API for XML (JAXP) – SAX

What is SAX SAX stands for Simple API for XML. It is an event driven method of accessing elements of an XML document. The elements are accessed serially. The API fire events for each type of data that it finds. The user provides a Handler that can handle the various kinds of events thrown by … Read more

Java API for XML (JAXP) – DOM

What is DOM DOM is an Object representation of an XML, HTML or XHTML document. In this tutorial we will be dealing with only XML. DOM represents the XML as a Document tree. JAXP provides API for DOM implementation in Java. It also provides parsing interface which can be used to plugin different parsers (JAXP … Read more

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