This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Problem JAXB Unmarshaller if order of XML tags differs. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Problem JAXB Unmarshaller if order of XML tags differs." Watch "Problem JAXB Unmarshaller if order of XML tags differs." New topic
Author

Problem JAXB Unmarshaller if order of XML tags differs.

Yogesh Gandhi
Ranch Hand

Joined: Dec 05, 2008
Posts: 207
Hello friends,

I am a bit new to XSD and XML unmarshalling techniques. In past month I have learnt JAXB techniques of how to unmarshal an given XML into a JAVA object.

I am using Java web services developer pack for that purpose.

Can someone tell if the order of tags matter while umarshalling an XML?

I have an XML of type


I created an XSD of kind..



I generated the java files using JWSDP. and written the code for unmarshalling.

It works if child 1 comes before child2. In case child2 comes before child1, then it gives me an unmarshalling exception as follows




Does the order of tags should matter??? How can I get rid of this problem?

Does anyone has any clue?
Yogesh Gandhi
Ranch Hand

Joined: Dec 05, 2008
Posts: 207
I got the solution to my problem :

Someone answered.

This exception has been generated because JAXB follows grammar defined in XSD. In XSD you have used <xsd:sequence> which forces elements to be in-order.

Use <xsd:all> as follows to have un-ordered child. This will solve your problem.

<xsd:all>
<xsd:element name="child1" type="xsd:string" />
<xsd:element name="child2" type="xsd:string" />
</xsd:all>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem JAXB Unmarshaller if order of XML tags differs.
 
Similar Threads
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"AirAvailabilityRS")
JAXB 1.0 External Binding Customization: Binding Duplicate Elements in XML Schema
Schema not works with xjc and java lang reflect Invocation Target Exception error
How to modify XSD that allows XML to hold the base and derived element types in any order?
Problem with SOAP