XSD validation in VB .NET

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
 
M

Martin Honnen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top