Thursday, 14 April 2016

XML : Jaxb multiple xml unmarshalling

I have 2 xsd files, one which declares authors and one which declares books and imports authors from the other xsd.

For the author:

      <xs:schema targetNamespace="ro.utcluj.cs.model.author"                 xmlns:xs="http://www.w3.org/2001/XMLSchema"                 elementFormDefault="qualified">            <xs:element name="author">              <xs:complexType>                  <xs:sequence>                      <xs:element name="authorName" type="xs:string"/>                      <xs:element name="authorAge" type="xs:integer"/>                      <xs:element name="CNP" type="xs:string"/>                  </xs:sequence>              </xs:complexType>          </xs:element>        </xs:schema>    

For the books:

  <xs:schema targetNamespace="ro.utcluj.cs.model.book"             xmlns:xs="http://www.w3.org/2001/XMLSchema"             xmlns:author="ro.utcluj.cs.model.author"             xmlns:tns="ro.utcluj.cs.model.book"             elementFormDefault="qualified">        <xs:import namespace="ro.utcluj.cs.model.author" schemaLocation="author.xsd"/>        <xs:element name="book">          <xs:complexType>              <xs:sequence>                  <xs:element name="bookName" type="xs:string"/>                  <xs:element name="title" type="xs:string"/>                  <xs:element ref="author:author"/>                  <xs:element name="genre" type="tns:bookGenre"/>                  <xs:element name="quantity" type="xs:integer"/>                  <xs:element name="price" type="xs:integer"/>              </xs:sequence>          </xs:complexType>      </xs:element>        <xs:simpleType name="bookGenre">          <xs:restriction base="xs:string">              <xs:enumeration value="ACTION"/>              <xs:enumeration value="HISTORY"/>          </xs:restriction>      </xs:simpleType>      </xs:schema>    

I want to write some xml files and unmarshal them with Jaxb. Can I able to write the authors in one xml and the books in another xml, have Jaxb unmarshal them and then somehow merge them? Or due to the fact that books have a dependency on authors they both must be written in the same xml with their namespaces specified?

No comments:

Post a Comment