tags:

views:

81

answers:

1

I'm validating an XML file against a schema using XDocument.Validate and get validation messages which look something like this:

The 'http://www.blablah.co.uk/schemas/cbds%3ADOB' element is invalid - The value '1999-0dsf2-21' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema%3Adate' - The string '1999-0dsf2-21' is not a valid XsdDateTime value.

This doesn't look too user friendly and I was wondering if it's possible to customize this message in any way? It'd be nice if I could provide a tokenized string like:

The value {0} is invalid for the element {1}

+1  A: 

This is not a complete solution, but this might help you get to where you want to be.

I believe that method can take a ValidationEventHandler Delegate. In your delegate, you can access the XML node if the exception is a XmlSchemaValidationException. If it is, you can use the XmlSchemaValidationException.SourceObject property to retrieve the invalid xml node.

hjb417