>>>Perhaps somebody can contradict me but most parsers fail on the first error
because<<<

How 'bout a clarification instead of a contradiction?

If you have not hooked the ValidationEventHandler, the XmlValidatingReader will fail 
on the first error (and throw an exception) as
you surmise. However, if you do hook the ValidationEventHandler, then it will not 
throw exceptions and will continue to try to
validate the document until you stop calling Read().

The types of errors that cascade into multiple errors are usually of the 
non-well-formed-document variety, but there are many other
types of validation errors that can occur without causing a cascade of other 
validation errors.  For example, consider an entity
that has min/max range restrictions and the document contains a value for that entity 
that is out of range.

My experience has been that the non-well-formed-doc variety of errors gets ironed out 
in the dev/test cycle, leaving the other
variety of errors to occur in production[0]. Because of this, for the dev cycle (read: 
Debug builds) I don't hook the
ValidationEventHandler and just let it blow back right away. For production builds 
(read: Release builds) I do hook the
ValidationEventHandler and cache these until finished parsing the doc and then throw a 
custom exception containing the collection of
validation error messages. This gives the end users of the component, whether they are 
a UI or a Web Service consumer, a much better
experience because the don't have to submit, get error notification of one single 
error, fix the error, resubmit, get next error
notification, fix that one, resubmit, get next error notification, etc.  They can 
simply submit one time and get a list of all the
errors to fix.

Keep Smilin'
Ed Stegman

[0] A robust design for the creator of the XML doc would reject user data input 
outside of specified ranges and never send the doc
for processing, but for many scenarios (e.g. Web Service) you won't be able to control 
the robustness of the doc creator because
it'll be somebody from some other company, so you'll have to code as defensively as 
you can.


-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED]]On Behalf Of Philip Nelson
Sent: Sunday, February 16, 2003 5:46 PM
To: [EMAIL PROTECTED]
Subject: Re: XML Validation by XSD


> So every thing is good,
> but when enter an InValid XML (i.e. the XML data has more than one error in
> its data types according to XSD file), only the first error will be
> reported by XML validator, so what is the right way to let the XML
> validator to go through all the errors in XML and reporting them all.
> Thanks.

Perhaps somebody can contradict me but most parsers fail on the first error
because

1 - they parse a stream, not the whole thing at once, so it would hard to know
if a second error was caused by the first and so on
2 - the point of validation is to tell you you have an invalid document, much
simpler than trying to accurately tell you everthing that's wrong with a
document

Reply via email to