Create XML from XSD using Java

I am very much new to Java. I have an xsd and I need to create xml based on the xsd. I have seen that we can use JAXB to do the stuff. But I have seen xml examples which are simple in nature. I have a sample xsd as shown below which i need to convert to xml.

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <xs:schema xmlns:addml="http://www.arkivverket.no/standarder/addml"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://www.arkivverket.no/standarder/addml" elementFormDefault="qualified"
      version="8.2">
      <xs:annotation>
        <xs:documentation xml:lang="en">
          Changes made in versions up to 8.2 are not documented in this document.
          Updated 2014-08-15 and 2014-09-29, Terje Pettersen-Dahl:
          Version 8.3:
          1. Element reference in dataset made optional.
          2. Optional possibility for header-lines.
          3. FieldDefinitionReference made unique within an instance.
          4. Created this documentation section.

        </xs:documentation>
      </xs:annotation>
      <xs:element name="addml">
        <xs:complexType>
          <xs:sequence>
            <xs:element ref="addml:objectStore" maxOccurs="1"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="objectStore">
        <xs:complexType>
          <xs:sequence>
            <xs:element ref="addml:folder" minOccurs="0"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="folder">
        <xs:complexType>
          <xs:sequence>
             <xs:element ref="addml:folderProperties" minOccurs="0"/>
             <xs:element ref="addml:documents" minOccurs="0"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="documents">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="document" maxOccurs="unbounded" minOccurs="2">
              <xs:complexType>
                <xs:sequence>
                  <xs:element ref="addml:docProperties"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="docProperties">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="documentId" type="xs:string"/>
            <xs:element name="documentTitle" type="xs:string"/>
            <xs:element name="dateCreated" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
       <xs:element name="folderProperties">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="documentId" type="xs:string"/>
            <xs:element name="documentTitle" type="xs:string"/>
            <xs:element name="dateCreated" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>

     <?xml version="1.0" encoding="utf-8"?>
    <addml>
      <objectStore>
        <folder>
          <folderProperties>
            <documentId>str1234</documentId>
            <documentTitle>str1234</documentTitle>
            <dateCreated>str1234</dateCreated>
          </folderProperties>
          <documents>
            <document>
              <docProperties>
                <documentId>str1234</documentId>
                <documentTitle>str1234</documentTitle>
                <dateCreated>str1234</dateCreated>
              </docProperties>
            </document>
            <document>
              <docProperties>
                <documentId>str1234</documentId>
                <documentTitle>str1234</documentTitle>
                <dateCreated>str1234</dateCreated>
              </docProperties>
            </document>
          </documents>
        </folder>
      </objectStore>
      </addml>

I need a XML like above. Note: I got the below XML using online converter.

Please help in creating the xml using Java. Any help is much appreciated.
Thanks, Mark

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s