Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Problem JAXB Unmarshaller if order of XML tags differs.

 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
And then the flying monkeys attacked. My only defense was this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic