471,582 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 software developers and data experts.

Not receiving errors when validating non-valid document

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
1 2744
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.

Similar topics

2 posts views Thread by Sudip Chakraborty | last post: by
2 posts views Thread by bildad | last post: by
2 posts views Thread by ninja_kornjaca | last post: by
3 posts views Thread by mpar612 | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.