473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 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 2856
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sudip Chakraborty | last post by:
Is there a way to see constraint validation errors while loading xml into a DataSet ? I'm interested in the line number in the xml file which is causing the error. I've enclosed the relevant stack...
1
by: Derek | last post by:
I am writing a web application for job seekers, and am adding a section that allows administrators to upload jobs to the system via xml. I have used an xml schema to validate the xml they upload....
1
by: Prodika | last post by:
With the 1.0 Framework, I've worked out using the XmlValidatingReader. Since I'm using the validation errors as feedback to the end user, I'm hoping to get away from techy messages such as "The...
2
by: bildad | last post by:
The following 'book example' of validating input seems to be incomplete. Since it is a beginner's book it may be intentional for simplicity. But I would like to know how to make this program work...
0
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this...
2
by: ninja_kornjaca | last post by:
Hello, I'm having a pretty strange problem and I'd appreciate if anyone could help me with it. I'm having a custom error page on my IIS. Specifically, I've written my own ASP (classic ASP)...
3
by: mpar612 | last post by:
I have code below (due to length I only included a portion). I am validating an email address. It checks to see if the email field is blank, in the proper format, etc... It prints errors to the...
25
by: JJ | last post by:
I only want to catch 404 errors at the application level (the rest are will be handled by the customerrors section of the web.config). How do I check for the error code in the Application_Error...
0
by: pauland80 | last post by:
<snip> <snip> Late thanks for your both answers! (Please excuse me for that) The problem was a bug in the device firmware. But before finding this, I dugg lightly in the pyserial source...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.