0

My Sample XSD:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

   <xsd:element name="customer" type="customer-type"/>

   <xsd:complexType name="customer-type">
      <xsd:sequence>
     <xsd:element name="name" type="xsd:string"/>
     <xsd:element name="billing-address" type="address-type"/>
     <xsd:element name="shipping-address" type="address-type"/>
  </xsd:sequence>
   </xsd:complexType>


  <xsd:complexType name="address-type">
  <xsd:sequence>
     <xsd:element name="street" type="xsd:string"/>
     <xsd:element name="city" type="xsd:string"/>
  </xsd:sequence>
 </xsd:complexType>

</xsd:schema>

My Sample XML:

<?xml version="1.0" encoding="utf-8"?>
<customer>
  <name>str1234</name>
  <billing-address>
  <street>str1234</street>
  <city>str1234</city>
  </billing-address>
  <shipping-address>
   <street>str1234</street>
   <city>str1234</city>
  </shipping-address>
</customer>

I have generated Pojos using the JAXB wizard in Eclipse. It resulted in three classes. AddressType.java, CustomerType.java and ObjectFactory.java

However no class is generated for the element Customer.

EDIT: How to use the un-marshaller in jaxb to retrieve the values without the Customer Pojo Class.

  • Possible duplicate of [convert xml to java object using jaxb (unmarshal)](https://stackoverflow.com/questions/11221136/convert-xml-to-java-object-using-jaxb-unmarshal) – daniu Mar 28 '18 at 07:08

1 Answers1

0

Your customer element is empty, that is why Customer.java isn't generated. You should add some elements to customer element something like below:

<xsd:element name="customer">
   <xsd:complexType>
         <xsd:sequence>
            <xsd:element name = 'customerdetails' type = 'customer-type' />
               <xsd:element name = 'address' type = 'address-type' />
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>

Also, in any case, if you intend to get the values from the xml without having POJO's then you can just parse it using sax or dom parsers.

Rahul
  • 637
  • 5
  • 16