users@jaxb.java.net

Re: xsd sequence

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Fri, 18 Jul 2008 13:17:35 +0200

Hi.

> I am using JAXB-1.0.5 for Marshaling and Unmarshaling.
>
>
>
> Currently I am having problem with the sequence of elements within the
> element of XSD. Please consider following scenario.
>
>
>
> The XSD contains the complex element as
>
>
>
> <xsd:complexType name="MyObject">
>
> <xsd:sequence>
>
> <xsd:element name="A" type="xsd:string" minOccurs="0"
> maxOccurs="unbounded"/>
>
> <xsd:element name="B" type="xsd:string" minOccurs="0"
> maxOccurs="unbounded"/>
>
> <xsd:element name="C" type="xsd:string" minOccurs="0"
> maxOccurs="unbounded"/>
>
> ` </xsd:sequence>
>
> </complexType>
>
>
>
> But the xml which I am getting in which the order of Element A or B or C
> (under complexType MyObject) is not in given sequence of XSD. It is coming
> in any sequence
>
>
>
> Eg.
>
> <MyOBject>
>
> <C>Element </C>
>
> <A>Element </A>
>
> <B>Element </B>
>
> </MyOBject>
>
>
>
>
>
> <MyOBject>
>
> <B>Element </B>
>
> <C>Element </C>
>
> <A>Element </A>
>
> </MyOBject>
>
>
>
> and because of this at the time of unmarshall I am getting parsing error.
> Can any one has any idea how can I resolve this problem.

What I usually do in such situations is pre-process the XML with an
ordering XSLT which puts elements in the correct order.

This ordering XSLT can be written manually or generated automatically.
I've attached an Order.xslt which I use to produce ordering XSLTs.
Apply this XSLT on your schema and you'll get an ordering XSLT. This
Order.xslt is not universal, but works in many cases.

Bye.
/lexi