473,545 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Val idate() method, the
..NET 2.0 version of XmlValidatingRe ader using the XmlReaderSettin gs and
XmlReader, and I briefly looked at XmlSchemaValida tor.

My current code is:

//--------------------------------------------------------------------------------------------------
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(" http://www.ups.com/cach/tofc/citta/updater",
"\\\\ilhodsvr00 4c\\cach\\upsap ps\\tofc\\citta \\updateSchema. xsd");

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

XmlDocument doc = new XmlDocument(nsm anager.NameTabl e);
doc.Load(filePa th);
doc.Schemas = schemaSet;
doc.Validate(ne w ValidationEvent Handler(validat ionCallback));
//---------------------------------------------------------------------------------------------------

The validationCallb ack function is the one that is in MSDN. I cannot
figure out why validationCallb ack never gets called. The reason that I
have the XmlNamespaceMan ager 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 2867
Your sample code should work, please share your XSD and XML files.

Zafar
"Chris Lieb" <ch********@gma il.com> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.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.Val idate() method, the
.NET 2.0 version of XmlValidatingRe ader using the XmlReaderSettin gs and
XmlReader, and I briefly looked at XmlSchemaValida tor.

My current code is:

//--------------------------------------------------------------------------
------------------------ XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(" http://www.ups.com/cach/tofc/citta/updater",
"\\\\ilhodsvr00 4c\\cach\\upsap ps\\tofc\\citta \\updateSchema. xsd");

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

XmlDocument doc = new XmlDocument(nsm anager.NameTabl e);
doc.Load(filePa th);
doc.Schemas = schemaSet;
doc.Validate(ne w ValidationEvent Handler(validat ionCallback));
//--------------------------------------------------------------------------
-------------------------
The validationCallb ack function is the one that is in MSDN. I cannot
figure out why validationCallb ack never gets called. The reason that I
have the XmlNamespaceMan ager 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
5163
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 trace below. at System.Data.DataSet.FailedEnableConstraints() at System.Data.DataSet.EnableConstraints() at...
1
18315
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. The website runs on IIS5 using classic ASP, and the xml validation is done in a .NET component written in C# that is registered for COM interop on...
1
1369
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 'http://tempuri.org/XMLFile1.xsd:MaxDependents' element has an invalid value according to its data type. An error occurred at...
2
5193
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 for all invalid input. Just for example, if user inputs 'abc' an error is caught, but if user inputs '432' the program hangs. Any clarification...
0
5404
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 board. I have a form that contains a ListView and a GroupBox control. The GroupBox control itself contains several TextBox Controls. I have...
2
1823
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) error page for "404 Not Found" error. It does some work in database (via. ADO), and the redirects user to another page. No big deal. And it worked...
3
1316
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 screen and everything works perfectly, but the errors always print at the very top of the page and I am having difficulty moving those errors around...
25
2346
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 of Global.asax ? Thanks, JJ
0
596
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 and found (to take with care!) :
0
3555
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 supposed to do the following: monitor ALL INCOMING TCP traffic on the local computer, and save certain parts of it as files - not log files though, but...
0
7410
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7923
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.