W3C home > Mailing lists > Public > xmlschema-dev@w3.org > May 2011

Re: Perform XML Schema validation at run-time?

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Mon, 16 May 2011 17:16:39 -0400
Message-Id: <>
To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
At 2011-05-16 16:26 -0400, Costello, Roger L. wrote:
>"XML Schema validation should only be done during testing and 
>debugging. It should never be done at run-time."
>Do you agree with that statement?

I do not.

I interpret your "testing and debugging" involves confirming the 
operation of a program.

Document validation (by way of schemas, or Schematron, or whatever) 
involves confirming instances satisfy expressed document constraints.

You are speaking of two different issues.  If you only turned on 
validation of instances during testing, what sense does that make if 
production instances violate the document constraints?  No doubt your 
test instances will pass muster if you validate them during your 
testing and debugging.

But that has no relation to an invalid instance arriving in a 
production environment.  I would think schema validation would be 
critical in an environment where foreign content is about to be 
processed ... without validation your application is assuming the 
content is correct (as it was in your test environment).  That is 
likely an unsafe assumption.

Or, you "simply" re-implement all your document constraint checking 
in your application, which negates the need for a schema expression 
in the first place.

By "foreign content" I mean instances generated by someone else or 
some other process than the processes you've confirmed generate 
instances correctly.  In a closed environment where you have some 
assurance that your instances don't need to be validated, then they 
don't need to be validated.  But in a networking environment where 
you are not in control of the instance being acted on, then 
validating against a schema expression outside all your programs 
means you don't have to duplicate the constraint checking inside each 
of your programs.

>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?

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
Received on Monday, 16 May 2011 21:17:13 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:59 UTC