Skip to main content

JAXB Unmarshalling issue incase of Repeating elements

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2011-02-21

Hi All
Iam using JAXB to unmarshall an xml file . But its not working as expected when there are repeating elements in the xml file . please find my xsd below.
<?xml version="1.0" encoding="ISO-8859-1" ?>
xmlns:xsd="" xmlns:jxb="" jxb:version="2.0">

<xsd:element name="name" type="xsd:string"/>
<xsd:element name="address" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="note" type="xsd:string"/>
<xsd:element name="quantity" type="xsd:positiveInteger"/>
<xsd:element name="price" type="xsd:decimal"/>

<xsd:complexType name="shipto.content">
<xsd:element ref="name"/>
<xsd:element ref="address"/>
<xsd:element ref="city" minOccurs="1" maxOccurs="1">
<jxb:property name="city1"/>

<xsd:element ref="country" minOccurs="1" maxOccurs="1">
<jxb:property name="country1"/>

<xsd:element ref="city" minOccurs="0">
<jxb:property name="city2"/>
<xsd:element ref="price"/>
<xsd:element ref="country" minOccurs="0" >
<jxb:property name="country2"/>
<xsd:element ref="quantity"/>
<xsd:element name="shipto" type="shipto.content"/>
<<<XML input >>>>
<?xml version="1.0" encoding="UTF-8"?>
<shipto xmlns:xsi="" xsi:noNamespaceSchemaLocation="../xsd/Customer_withAnnotation.xsd">

Iam passing an xml file complaint to this xsd for unmarshalling .My java code is a simple unmarshalling nothing more than that . But after unmarshalling , if i try to get the value of 2nd repeating element it is coming as null . Can any one please help me .

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2011-03-25

dear nagasreekrishna,
There is actually a problem with your schema. the xsd:element name="shipto" type="shipto.content" allows only three elements. I recommend have a look at the examples in the jaxb reference implementation to get a feeling
how to design a suitable schema.