Hi Jeremy,

Castor's validators validate the object model and not the XML instance,
so it doesn't validate against XML order. You can easily enable this by
using the underlying parser's validator instead which will validate
against the XML while Castor is performing the unmarshalling.  

This can be enabled in the castor.properties file.

In the future Castor will provide validation against "order" as well,
it's just a bit more tricky since this type of validation needs to be
done during the unmarshalling proces itself and not after it's been
completed (since Java doesn't have anyway to specify the order of
fields).

In the meantime however, feel free to use the parser validation.

--Keith


Jeremy Warach wrote:
> 
> I have just started using Castor XML with the Source Generator.  I have an
> existing XML Schema (.xsd) file, and I generated the source for it using the
> default options of the Source Generator.  I want to perform strict
> validation of an XML file coming from a client against the existing schema,
> so I am executing the following code:
> 
>     Unmarshaller unmarshaller = new Unmarshaller(Order.class);
>     try {
>       Order order = (Order)unmarshaller.unmarshal(reader);
>     }
>     catch ( Exception e )
>     {
>       System.out.println( e.getMessage() );
>     }
> 
> The root element of the schema is <Order>.  I expect that any validation
> error will throw an exception.  This code works fine for identifying
> mis-spelled element names, or enumerations with invalid content, but it does
> not identify if an element is in the wrong place in the XML file.  For
> example, the schema specfies that the correct order of elements is (in
> part):
> 
> <Order>
>     <Order_No>text</Order_No>
>     <Product_Type>enumeration</Product_Type>
>     <Special_Instructions>text</Special_Instructions>
> </Order>
> 
> But Castor will allow the following XML without throwing an exception:
> 
> <Order>
>     <Product_Type>enumeration</Product_Type>
>     <Order_No>text</Order_No>
>     <Special_Instructions>text</Special_Instructions>
> </Order>
> 
> According to "strict" XML Schema validation rules, elements must appear in
> the correct order as specified by the schema.  Is there any way to have
> Castor enforce this?
> 
> Thank you,
> Jeremy
> 
> _________________________________________________________________
> Express yourself with the new version of MSN Messenger! Download today -
> it's FREE! http://messenger.msn.com/go/onm00200471ave/direct/01/
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-user



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

Reply via email to