In this section we shall map a Java class, containing elements and attributes declared using the annotations API in the javax.xml.bind.annotation
package.
Create a Java class—Catalog.java
. Specify the root element using the @XmlRootElement
annotation. Specify the root element's name and the namespace. Specify the property order within the root element using the @XmlType
annotation's propOrder
element:
@XmlRootElement(name="catalog", namespace="http://www.example.org/catalog")@XmlType(name = "", propOrder = { "publisher", "edition", "title", "author" }) public class Catalog { }
Specify declarations and getter/setter methods for the properties. Specify a journal
attribute using the @XmlAttribute
annotation:
@XmlAttribute public String journal;
The annotated class—Catalog.java
is listed, as follows:
package jaxb; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlType; @XmlRootElement(name="catalog...