Unmarshalling an XML document
In this section, we shall unmarshal an XML document using the JAXB API and the Java classes generated by compiling the example XML schema. A prerequisite for unmarshalling is that the XML document should conform to the XML schema from which the binding classes are generated. The XML document that we shall unmarshal is the same that is marshalled in the previous section. Create a Java application, JAXBUnMarshaller.java
, in JDeveloper project JAXB
similar to the JAXBMarshaller
application. In the JAXBUnMarshaller
class import the JAXB API package. As JAXBUnMarshaller.java
is created in the same package as the binding classes, the binding classes do not need to be imported.
import javax.xml.bind.*;
Create a JAXBContext
object using static method newInstance(String contextPath). ContextPath
is a colon-separated list of packages that contain the schema-derived binding classes.
JAXBContext jaxbContext=JAXBContext.newInstance("jaxb");
Create an Unmarshaller
object...