473,612 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using XmlValidatingRe ader to validate XML Schema

The XmlValidatingRe ader seems to have changed drastically in .Net
Frameworks 1.0 SP3 and beyond with regards to validating XML files that
are XML Schemas.

Consider the following code:
---
class ValidatingSchem a
{
[STAThread]
static void Main(string[] args)
{
string xmlData = @"<xs:schema mlns:xs='http://www.w3.org/2001/XMLSchema' >
<xs:element name='root' />
<xs:cement id='foo'/>
</xs:schema>";
XmlTextReader reader = new XmlTextReader(n ew StringReader(xm lData));
XmlValidatingRe ader vreader = new XmlValidatingRe ader(reader);
vreader.Validat ionType = ValidationType. Schema;
vreader.Validat ionEventHandler += new ValidationEvent Handler(PrintEv ent);
while(vreader.R ead())
{}
vreader.Close() ;
}

private static void PrintEvent(obje ct source, ValidationEvent Args info)
{
Console.WriteLi ne(info.Message );
}
}
---
If I compile and run this under .Net 1.0.3705.0 I get the following output.
===
The 'http://www.w3.org/2001/XMLSchema:cemen t' element is not supported
in this context. An error occurred at (3, 7).
===
This tells me that the validation is checking my input file against some
internal knowledge of what an XML Schema can contain. After I apply .Net
FW 1.0 SP3 I get the following output from the same code:
===
Could not find schema information for the element
'http://www.w3.org/2001/XMLSchema:schem a'. An error occurred at (1, 2).
Could not find schema information for the element
'http://www.w3.org/2001/XMLSchema:eleme nt'. An error occurred at (2, 7).
Could not find schema information for the attribute 'name'. An error
occurred at (2, 18).
Could not find schema information for the element
'http://www.w3.org/2001/XMLSchema:cemen t'. An error occurred at (3, 7).
Could not find schema information for the attribute 'id'. An error
occurred at (3, 17).
===
It appears that the internal knowledge about XML Schema is gone?
When I compile and run this under .Net framework version 1.1 I get the
following (different) output:
===
Could not find schema information for the element
'http://www.w3.org/2001/XMLSchema:eleme nt'. An error occurred at , (2, 7).
Could not find schema information for the attribute 'name'. An error
occurred at , (2, 18).
Could not find schema information for the element
'http://www.w3.org/2001/XMLSchema:cemen t'. An error occurred at , (3, 7).
Could not find schema information for the attribute 'id'. An error
occurred at , (3, 17).
===
Is this change a bug? Or is it how XmlValidatingSc hema is supposed to
work? Why did the behaviour change so much in a service pack?

Ultimately, I want to be able to valid XML Schemas that contain elements
from several different namespaces against their respective schemas.
XmlValidatingRe ader seems like the tool to use, but it doesn't work
consistantly across versions. Is there another better way?

Thanks,
Harold Putman
Nov 12 '05 #1
0 4675

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5656
by: Bob Rosen | last post by:
My message concerns a sample application that I took verbatim from the book titled "SAMS Teach Yourself Visual Basic.NET Web Programming in 21 days". It consists of a web page that takes the names of an XML file and corresponding XML schema (XSD) file as input (via text boxes) and is supposed to perform a validation on the XML file. When I run it, I get the following error message after entering the file names and clicking on the...
3
6638
by: Mike P | last post by:
I have an xml doucument that I want to validate with a XSD schema. I'm new to this and I don't know exactly how I make the references at the top of the documents so that the XSD file will validate the XML file in my C# program. My code is below : change.xml : <?xml version="1.0"?> <rsp-vcn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="change.xsd"
4
1603
by: Adam Smith | last post by:
XmlValidatingReader too sensitive? I have the following schemas (simplified) and xml file which validate fine in xmlspy, but blow up in xmlvalidatingreader with: 'The 'Hierarchy' element is not declared. An error occurred'. Any help appreciated. To give a brief explanation of what I'm trying to do, the schema 1 is a
1
2967
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. The problem I am having is that the validation event fires for each node in the xml. It seems to be completely ignoring the schema that I have used. I'm wondering if I need to do something extra to tell the xml which schema to use.
1
1587
by: Andreas Palm | last post by:
Hi there, I do have a dataset which I use to write a XML file with inline schema. A second application should use a XmlvalidatingReader to read the xml file again. Now I get errors like: The 'http://tempuri.org/LicenceFile.xsd:LicenceData' element is not declared.
1
9101
by: aevans1108 | last post by:
Greetings All If this is the wrong place to post this question, please give me a push in the right direction. Thanks. I know there has to be a simpler way to do this, but this is as simple a way as I could come up with. Yes, it's obvious I don't know what I'm doing. I'm creating an XSD string and an XML string at runtime (ie: NOT read
2
7169
by: josh | last post by:
Hi, I am trying to validate cXML documents against cXML.dtd using the XmlValidatingReader. If I set the XMLValidatingReader's ValidatingType to ValidationType.DTD, I get the following System.Xml.Schema.XmlSchemaException: "The parameter entity replacement text must nest properly within markup
1
1837
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST> xml file 2
12
8549
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST>
0
8105
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8605
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8565
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8246
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
4045
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4109
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2550
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
1695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1413
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.