472,981 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 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 2826
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.