By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,141 Members | 1,880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,141 IT Pros & Developers. It's quick & easy.

Not receiving errors when validating non-valid document

P: n/a
I have an XML Schema file that I know is correct becuase I currently
use it in a VB6 program to validate XML documents. Also, if I load an
XML file into VS2005 that is not valid against this schema, I get XML
errors (blue squigglies) in a few places, which indicates to me that I
should get validation errors while validating through code.

When I try to validate an invalid document, I never get any validation
errors. I have tried many different ways for validating an XML
document using an XSD, including the XmlDocument.Validate() method, the
..NET 2.0 version of XmlValidatingReader using the XmlReaderSettings and
XmlReader, and I briefly looked at XmlSchemaValidator.

My current code is:

//--------------------------------------------------------------------------------------------------
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("http://www.ups.com/cach/tofc/citta/updater",
"\\\\ilhodsvr004c\\cach\\upsapps\\tofc\\citta\\upd ateSchema.xsd");

XmlNamespaceManager nsmanager = new XmlNamespaceManager(new
NameTable());
nsmanager.AddNamespace(String.Empty,
"http://www.ups.com/cach/tofc/citta/updater");
nsmanager.AddNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance");

XmlDocument doc = new XmlDocument(nsmanager.NameTable);
doc.Load(filePath);
doc.Schemas = schemaSet;
doc.Validate(new ValidationEventHandler(validationCallback));
//---------------------------------------------------------------------------------------------------

The validationCallback function is the one that is in MSDN. I cannot
figure out why validationCallback never gets called. The reason that I
have the XmlNamespaceManager in there is becuase when I was working on
the VB6 app, I had to define a namespace for the validation to work,
otherwise it never associated the schema with the default namespace.

Could this be caused by the fact that the document that I am validating
has no XML declaration, default namespace, or xsi namespace with
schemaLocation?

Does anyone know why I am not getting any validation errors?

Thanks,
Chris

Jun 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Your sample code should work, please share your XSD and XML files.

Zafar
"Chris Lieb" <ch********@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
I have an XML Schema file that I know is correct becuase I currently
use it in a VB6 program to validate XML documents. Also, if I load an
XML file into VS2005 that is not valid against this schema, I get XML
errors (blue squigglies) in a few places, which indicates to me that I
should get validation errors while validating through code.

When I try to validate an invalid document, I never get any validation
errors. I have tried many different ways for validating an XML
document using an XSD, including the XmlDocument.Validate() method, the
.NET 2.0 version of XmlValidatingReader using the XmlReaderSettings and
XmlReader, and I briefly looked at XmlSchemaValidator.

My current code is:

//--------------------------------------------------------------------------
------------------------ XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("http://www.ups.com/cach/tofc/citta/updater",
"\\\\ilhodsvr004c\\cach\\upsapps\\tofc\\citta\\upd ateSchema.xsd");

XmlNamespaceManager nsmanager = new XmlNamespaceManager(new
NameTable());
nsmanager.AddNamespace(String.Empty,
"http://www.ups.com/cach/tofc/citta/updater");
nsmanager.AddNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance");

XmlDocument doc = new XmlDocument(nsmanager.NameTable);
doc.Load(filePath);
doc.Schemas = schemaSet;
doc.Validate(new ValidationEventHandler(validationCallback));
//--------------------------------------------------------------------------
-------------------------
The validationCallback function is the one that is in MSDN. I cannot
figure out why validationCallback never gets called. The reason that I
have the XmlNamespaceManager in there is becuase when I was working on
the VB6 app, I had to define a namespace for the validation to work,
otherwise it never associated the schema with the default namespace.

Could this be caused by the fact that the document that I am validating
has no XML declaration, default namespace, or xsi namespace with
schemaLocation?

Does anyone know why I am not getting any validation errors?

Thanks,
Chris

Jun 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.