473,379 Members | 1,200 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,379 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 2854
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.