Re: Perform XML Schema validation at run-time?

gkholman@CraneSoftwrights.com wrote on 05/16/2011 05:16:39 PM:

> >Can you provide an example of a service that does run-time validation?
>
> I would think that any application that is using something like JAXB
> would need to pre-validate their foreign-sourced instances.  While I
> don't have personal experience using JAXB, I've been led to believe
> that it will choke trying to convert an instance into Java objects
> when that instance does not match the schema used to synthesize the
> object-building code.  Perhaps I've been misled.  But, if true, and
> the foreign instance doesn't validate, your program won't run because
> it cannot build the objects in memory from the XML angle
> brackets.  You are stuck from even inspecting the instance because
> the objects are not loaded up when the program runs.
>
> Perhaps others on this list can comment about the JAXB scenario I've
> described above.  Does the application abend on an instance that
> doesn't validate to the constraints built into the object-building
> code synthesized by the schema?

Quite the opposite. JAXB 2.x was designed to tolerate invalid input and can
sometimes make a document valid on a round-trip through unmarshal/marshal.
Invalid values and unknown elements/attributes are ignored.

If you don't want invalid documents to be accepted quietly you can register
a schema (not necessarily XML Schema; could also be Relax NG, Schematron or
something else) and if you want you can force JAXB to fail if an error is
reported by the validator or respond in some other way with the error
handler you've registered.

> If so ... then I would think schema validation at runtime would be
> critical in a networking environment where you don't have control
> creating the content.
>
> I hope this helps.
>
> . . . . . . . . . Ken
>
> --
> Contact us for world-wide XML consulting & instructor-led training
> Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
> G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
> Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Received on Monday, 16 May 2011 23:25:59 UTC