On Mon, 24 Mar 2003 08:23:35 -0800, Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM> wrote:
>> I decided not to use unmarshall-time validation because the supplier of
>> the data doesn't know anything about XML. Actually I have to convert
>> his data to XML on the fly before unmarshalling. This will change in
>> the future, but for now the most useful info I could give him would be
>> to tell him which data values are invalid and why.
>
>If you don't do the unmarshal-time validation, JAXB RI will allow
>invalid inputs to be accepted. But there's no guarantee that
>unmarshalled object is in the invalid state.
>IOW, you may miss some validity errors if you just rely on the on-demand
>validation.
>
>Consider the following simple schema:
>
> <xs:element name="root" type="xs:boolean" />
>
>with a broken input:
>
> <root undefined="att"> true </root>
>
>without any error/warning, and even if you do the on-demand validation
>right after the unmarshalling, you won't get any error.
Thanks...I hadn't thought of that.
>
>Assuming your data converter is written in Java, what you can do is to
>change it to generate SAX events or DOM tree --- anything other than
>textual representation. Then you can feed them directly into JAXB (or
>any other tool that can consume XML.)
>
>In this way you can maintain the association between the original data
>and its XML form, you can easily associate the error from JAXB
>unmarshaller to the portion of data in the input.
This is basically what I'm doing ... I think I just need to get the implementation details straight.
>
>> Actually I'm using noNamespaceSchemaLocation. That still works for me
>> when I do a straight SAX parse. Could it be causing a problem now? The
>> schema from which I generated my JAXB classes does not have a namespace.
>
>There's a difference between "no namespace" and "before namespace". The
>latter is the compatibility mode for those applications which are
>written before XML Namespace is invented, and that's what you are using
>in your code.
>
>So you should be really turning on the namespace processing. XML Schema
>is defined on top of XML Namespace, and it doesn't mix with the "before
>namespace" mode.
>
>> parser.setFeature( "http://xml.org/sax/features/namespaces", false);
>
>change this to:
>
>parser.setFeature( "http://xml.org/sax/features/namespaces", true);
Thanks, that worked. I misunderstood what that feature did ... the distinction between "no namespace" and "before namespace" was the key.
>regards,
>--
>Kohsuke KAWAGUCHI 408-276-7063 (x17063)
>Sun Microsystems kohsuke.kawaguchi_at_sun.com