In this article, let us see how to avoid converting < to < ; and > to > ; and & to & ; during JAXB Marshalling operation.
1. CharacterEscapeHandler creation
Create a custom Escape Handler by implementing the CharacterEscapeHandler interface as given below.
This article describes the method of generating the JAXB Stubs from the XML schema using ANT build.
Consider the following ANT build xml which reads the XML schema from "C:\Sample.xsd" and generates the JAXB stubs in the "C:\jaxbSrc" location.
<project basedir="." default="build" name="Jaxb-StubGenerationDemo">
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<fileset dir="C:\lib\" includes="jaxb-xjc.jar" />
JDOM is simply a Java representation of an XML document. It provides a way to represent that document for efficient parsing, manipulation, and writing. It has a straightforward API, which is optimized for the Java programmer. It's an alternative to DOM and SAX, although it integrates well with both DOM and SAX. It also integrates with other xml parsers like xerces.
The following class has methods for creating and parsing an xml document using JDom.
In this article lets discuss about how to convert a Java bean to XML document.
Have look at the following Java bean.
public Device(long deviceId, String deviceName, String productId, String serialNo)
this.deviceId = deviceId;
this.deviceName = deviceName;
this.productId = productId;
this.serialNo = serialNo;
private long deviceId;
private String deviceName;
private String productId;
private String serialNo;
In this article, let us see how to validate XML file against the XML Schema.
Let us take a simple XML Schema file as follows,
<xs:attribute name="Name" type="xs:string"/>
<xs:attribute name="Country" type="xs:string"/>
Lets us construct the XML file which we will use to validate with the Schema.