473,322 Members | 1,806 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,322 software developers and data experts.

XML schemas .NET 2.0

I have an XML schema and I am trying to validate any XML document sent
against it.

Here's some of the code:
XmlReaderSettings xmlReaderSettings = new
XmlReaderSettings();
xmlReaderSettings.Schemas.Add(@"http://myschema/myschema.xsd",
"myschema.xsd");
xmlReaderSettings.ValidationEventHandler += new
ValidationEventHandler(ValidationEvent);

xmlReaderSettings.ValidationType = ValidationType.Schema;

xmlReaderSettings.ValidationFlags =
xmlReaderSettings.ValidationFlags |

XmlSchemaValidationFlags.ReportValidationWarnings;
XmlReader xmlReader = XmlReader.Create(myXmlDocument,
xmlReaderSettings);

while(xmlReader.Read());

Now, my problem is, if I specify an XML document which breaks the
schema with a <Root xmlns='http://myschema/myschema.xsd'> it throws an
XmlSchemaValidationException - which is good.

However, if I, or the client of my service omits the xmlns tag then
there is no error thrown. If I add an ValidationEventHandler I find
that the difference is that when the schema is specified it is an
XmlSeverityType.Error where as if no xmlns is given it is only an
XmlSeverityType.Warning.

Why? Why? Why? Why? Why? The XML document is wrong, it doesn't
validate. I have told it to validate against the schema the idea being
that if my client(s) send it incorrectly it fails. Yet they can now
get around the validation by not declaring the schema in the XML
document. To me this is stupid, stupid, stupid. Surely one of the
main ideas of the schema is that we do not wholly trust the originator
of the XML to be correct so we wish to check?

Basically - is there anyway around this?

Dec 5 '05 #1
1 2837
If the root of the XML document can not be strictly validated, because of
either

1. lack of element declaration of that item
2. lack of type present based on the xsi:type attribute on that element.

then LAX validation is performed as if the type of that element is
xs:anyType. You will get a validation warning in such cases, not errors. You
should filter for Warnings as well as Errors while accepting these XML
documents.

You can look up the XSD spec which specifies this behavior at:
http://www.w3.org/TR/2004/PER-xmlsch...cvc-assess-elt

Thanks,
Zafar

<pe********@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
I have an XML schema and I am trying to validate any XML document sent
against it.

Here's some of the code:
XmlReaderSettings xmlReaderSettings = new
XmlReaderSettings();
xmlReaderSettings.Schemas.Add(@"http://myschema/myschema.xsd",
"myschema.xsd");
xmlReaderSettings.ValidationEventHandler += new
ValidationEventHandler(ValidationEvent);

xmlReaderSettings.ValidationType = ValidationType.Schema;

xmlReaderSettings.ValidationFlags =
xmlReaderSettings.ValidationFlags |

XmlSchemaValidationFlags.ReportValidationWarnings;
XmlReader xmlReader = XmlReader.Create(myXmlDocument,
xmlReaderSettings);

while(xmlReader.Read());

Now, my problem is, if I specify an XML document which breaks the
schema with a <Root xmlns='http://myschema/myschema.xsd'> it throws an
XmlSchemaValidationException - which is good.

However, if I, or the client of my service omits the xmlns tag then
there is no error thrown. If I add an ValidationEventHandler I find
that the difference is that when the schema is specified it is an
XmlSeverityType.Error where as if no xmlns is given it is only an
XmlSeverityType.Warning.

Why? Why? Why? Why? Why? The XML document is wrong, it doesn't
validate. I have told it to validate against the schema the idea being
that if my client(s) send it incorrectly it fails. Yet they can now
get around the validation by not declaring the schema in the XML
document. To me this is stupid, stupid, stupid. Surely one of the
main ideas of the schema is that we do not wholly trust the originator
of the XML to be correct so we wish to check?

Basically - is there anyway around this?

Dec 6 '05 #2

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

Similar topics

0
by: kyancy | last post by:
Hello All. We have several XML schemas to describe common component document parts. We then create new XML schemas as necessary that use "xsd:import schemaLocation=whateverLocation.." to include...
30
by: btober | last post by:
Whenever I create a temporary table, with something like CREATE TEMPORARY TABLE temptable1 AS SELECT * FROM paid.ad_hoc_query; New schemas appear, with names like "pg_temp_1". I guess the...
7
by: Roderick A. Anderson | last post by:
I'm looking for some input on a configuration I'm implementing. The long term goal is to providing hosting for companies and organizations with a basic/generic set of applications that use...
4
by: anonymous | last post by:
When I use the schema collection to apply many schemas to one XML instance document, I get an error if I do not qualify every element with the appropriate namespace. Both the W3C site and this...
2
by: John Jenkins | last post by:
Hi, I have a lot of schemas to load into a schema collection. I load them in by reading each one into a XMLTextReader from disk and add them into a schema collection. I have a couple of issues to...
1
by: CSN | last post by:
I have two machines between which I exchange dumps a lot. On the first (Windows/cygwin), pgsql was set up with "Administrator" as the main superuser - who owns all schemas in template0 and...
6
by: Dennis Gearon | last post by:
This post is as much about getting some questions answered as leaving the following definitions in the archives for the next person. After a quick perview of the web, I came up with the...
0
by: Net Virtual Mailing Lists | last post by:
I've been spending the last few days converting many databases into a single schema and have completed the process, but now I'm at somewhat of an impasse as to the best way to proceed forward.... ...
3
by: Sami Marzouki | last post by:
Hi, What I'm trying to do is: - To write a Web.config with custom sections. (Done) - To write a xsd schema for this custom sections.(Done) - Tell the Web.config to take the two schemas. When...
0
by: vihrao | last post by:
I am designing wsdl that uses multiple schemas. I can do this in two ways: 1) use multiple schema imports in one wsdl or 2) use multiple schema imports in to one common schema and then import a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.