W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2007

RE: when to validate XML while being created programmatically..

From: Michael Kay <mike@saxonica.com>
Date: Thu, 20 Dec 2007 10:32:51 -0000
To: "'dave'" <ceek63@yahoo.com>, <xmlschema-dev@w3.org>
Message-ID: <00ae01c842f3$ac3c53a0$6401a8c0@turtle>

> This is related to validating a brand new XML instance WHILE 
> being created programmatically:

If you use XSLT or XQuery to create the XML instance, and you enable
validation, then Saxon will insert a valldator into the serialization
pipeline and check each element/attribute as it is written. You can do the
same thing if you are generating XML from a Java application, though the API
might be a little low-level for your taste.

> If Yes, how would you 
> correct these validation errors programmatically? It looks 
> like a daunting task.

I've no idea how you would go about correcting validation errors
programmatically whether it's done on the fly or otherwise. If you're told
that an attribute value doesn't match the pattern facet for the attribute
type, what would you expect a program to do about it?
>  OR
> Does it even make sense to perform on-the-fly validation 
> while constructing a new XML instance? 

Yes, see above, it makes eminent sense.

> If Yes, how would you 
> tell the system when the instance is even incrementally valid 
> before turning ON the validation. 

Sorry, I don't understand the term "incrementally valid".

> I can imagine there must be 
> an API to enable/disable on-the-fly validation during the 
> creation of XML instance. I might be wrong as it may not make sense.

With Saxon (if you're really prepared to delve deep into the API) you can
enable validation at the level of an element node. You can't switch
validation off: once you're validating an element, you keep validating until
you get to the end of that element.
> Does the application design needs to ensure that the 
> generated XML is always valid?
Well, if the XML was always valid then you wouldn't need to validate it; but
I think you should treat a validation failure as an error either in the
application or perhaps (arguably) in its source data.

Michael Kay
Received on Thursday, 20 December 2007 10:33:09 UTC

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