3. ● Object (DOM, JDOM….etc)
● PUSH (SAX)
● PULL(Stax)
● JAXB(Java Architecture for XML Binding)
4. ● Defines an API for reading and writing Java objects to and from XML
documents.
● Don't need to be aware of XML parsing techniques
● No extra dependency needed (its inside JDK)
● Used as a standard in many cases
XML JAXB
Java
Objects
8. JAXB uses annotations to indicate the central elements.
Annotation Definition
@XmlRootElement(namespace = "namespace") Define the root element for an XML tree
@XmlType(propOrder = { "field2", "field1",.. }) Allows to define the order in which the fields are written in
the XML file
@XmlElement Define the XML element which will be used.
@XmlAttribute Define the attribute of an element
11. run the following command:
$xjc course-booking.xsd -p org.wso2.jaxb.training -d src/generated
● -d <dir>: Place the generated files into this directory.
● -p <package>: Place the generated files in this package.
● -nv: Don't perform strict validation of the input schema.
● -httpproxy <proxy>: Use this if you are behind a proxy. Takes the format [user[:password]@]proxyHost[:proxyPort].
● -classpath <arg>: Specify the classpath, if necessary.
● -readOnly: Generates read-only source code files, if your OS supports this.
There is also an equivalent ant task, which makes it quite easy to integrate into an Ant or Maven-based build process.
12.
13.
14.
15.
16.
17.
18. @XmlAttribute
For complete reference please visit : https://jaxb.java.net/tutorial/section_6_2_1-A-Survey-Of-
JAXB-Annotations.html#A%20Survey%20Of%20JAXB%20Annotations
19. JAXB advantages
o It is very simple to use than DOM or SAX
parser
o We can marshal XML file to other data
targets like inputStream,URL,DOM node.
o We can unmarshal XML file from other
data targets.
o We don't need to be aware of XML parsing
techniques.
o We don't need to access XML in tree
structure always.
JAXB disadvantages
o JAXB is high layer API so it has less
control on parsing than SAX or DOM.
o It has some overhead tasks so it is slower
than SAX.