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

> 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
http://www.saxonica.com/

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