XML / CATATAN</>↗XML14 Agt 2012
In this example you’ll learn how to use the JAXB @XmlElementWrapper annotation. This annotation can be used to generate a wrapper element around an XML element representation. When no name defined, the @XmlElementWrapper annotation uses the property name as the wrapper element name. Let’s see the code snippet below. Here is the code snippet for […]
XML / CATATAN</>↗XML13 Agt 2012
JAXB, Java Architecture for XML Binding, it uses JAXB annotations to convert POJO to or from XML file. In this example you will learn how to convert an object / POJO into an XML document using JAXB. The process of converting an object into XML also known as marshalling. In this snippet our POJO is […]
XML / CATATAN</>↗XML13 Agt 2012
The code snippet below show you how to convert POJO into XML file using JAXB. To do this we can pass the output file where we want the XML to be saved to the marshaller object. package org.kodejava.xml; import org.kodejava.xml.support.Track; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import java.io.File; public class JAXBObjectToXmlFile { public static void […]
XML / CATATAN</>↗XML13 Agt 2012
In this code snippet you can learn how to convert or unmarshall an XML file into it corresponding POJO. The steps on unmarshalling XML to object begin by creating an instance of JAXBContext. With the context object we can then create an instance of Unmarshaller class. Using the unmarshall() method and pass an XML file […]
XML / CATATAN</>↗XML13 Agt 2012
In this code snippet you will learn how to define the order of XML element generated by the JAXB API. To define the element order we need to use the @XmlType annotation in our POJO. This annotation propOrder attribute is where we define what element should come first and which element should be place at […]
XML / CATATAN</>↗XML13 Agt 2012
In the following code snippet you will learn how to change the default root element name of the XML generated by the JAXB API. By default, the name of the class is use as the root element name. To change the root element name we can use the name property of the @XmlRootElement annotation. In […]