I implemented the use of mapping files, and that did the trick, thank you!

-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 28, 2003 12:32 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] castor-xml - inconsistent element ordering on
generated xml string



Hi Gary,

If you are using Castor's default introspection to automatically map the
objects into XML, then there is no guarantee on the order. It simply
depends on the order in which the fields are returned to Castor using
the Java reflection API.

If you use a mapping file Castor will generate the XML in the order in
which the mapping file is specified.


One observation from your comments, currently in your design, you are
marshalling to a string, then creating a XML DOM from the string. You
can marshal directly to a XML DOM to save some overhead.

--Keith

"Trask, Gary" wrote:
>
> I'm using castor-xml to create an xml string from a java object.  After I create the 
> xml string from the java object, I add some additional data to the xml string using 
> the DOM xml parser, then I validate the xml against an xml schema.
>
> The validation step is failing sporadically because the xml schema requires elements 
> in the xml to be in a specific order (the element definitions in the schema are 
> bounded with <xs:sequence> and </xs:sequence>).  The problem is that Castor is not 
> being consistent about the field ordering.  I created the schema by creating the 
> java object, filling in all possible values on the object, then used Castor the 
> create an xml string from the object.  I then used xml spy to generate a schema from 
> the xml string.  When I run my application, sometimes the xml string is created and 
> validated successfully, the element order matches the sequence specified in the 
> schema.  Other times (appears to be random), the xml validation fails because Castor 
> will switch the order of two fields in the xml.
>
> I've searched for a way to modify my xml schema so that it isn't order sensitive 
> (i.e, use xs:all instead of xs:sequence), but since some of the elements have a 
> minOccurs="unbounded" constraint I can't do that.
>
> Has anyone else observed this inconsistency of element order in castor generated 
> xml?  If so, is there a way to configure castor to always put the elements in the 
> same order?
>
> The content contained in this electronic message is not intended to
> constitute formation of a contract binding TWTC.  TWTC will be
> contractually bound only upon execution, by an authorized officer, of
> a contract including agreed terms and conditions or by express
> application of its tariffs.
>
> This message is intended only for the use of the individual or entity
> to which it is addressed. If the reader of this message is not the
> intended recipient, or the employee or agent responsible for
> delivering the message to the intended recipient, you are hereby
> notified that any dissemination, distribution or copying of this
> message is strictly prohibited. If you have received this
> communication in error, please notify us immediately by replying to
> the sender of this E-Mail or by telephone.
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev


The content contained in this electronic message is not intended to
constitute formation of a contract binding TWTC.  TWTC will be
contractually bound only upon execution, by an authorized officer, of
a contract including agreed terms and conditions or by express
application of its tariffs.

This message is intended only for the use of the individual or entity
to which it is addressed. If the reader of this message is not the
intended recipient, or the employee or agent responsible for
delivering the message to the intended recipient, you are hereby
notified that any dissemination, distribution or copying of this
message is strictly prohibited. If you have received this
communication in error, please notify us immediately by replying to
the sender of this E-Mail or by telephone.

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to