XSD validation in VB .NET

  • Thread starter Thread starter Mic
  • Start date Start date
M

Mic

Hi,

I'm doing validation of a xml file with a xsd schema and it works
fine.

I get validation errors in the form:

«Message:{0} The 'NAM' attribute has an invalid value according to its
data type. An error occurred at file:///A:/myfile.xml, (526, 12).»

I can isolate line and column using the args.Exception.LineNumber and
args.Exception.LinePosition properties.

Unfortunately, there is no property to retrieve the element or
attribute name. I have to make a search in the Message string to get
it. And there is no apparent way of getting the value in fault.

Identifying errors is fine but then I need to correct them. I can do
corrections manually using the line and column positions but it's not
very practical for large files.

How can I link the informations given by the XmlValidatingReader to a
dataset or anything that can help me make modifications to correct the
errors ?

thanks
 
Mic said:
Unfortunately, there is no property to retrieve the element or
attribute name.

There is, cast the sender argument of your ValidationEventHandler to an
XmlReader and read out the Name property of the XmlReader.


How can I link the informations given by the XmlValidatingReader to a
dataset or anything that can help me make modifications to correct the
errors ?

Load into a System.Xml.XmlDocument, that way you get type annotations
(e.g.
<http://msdn2.microsoft.com/en-us/library/System.Xml.XmlElement.SchemaInfo.aspx>)
on the nodes in the XML document and you can manipulate and revalidate
as needed.
 
Back
Top