473,405 Members | 2,262 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,405 software developers and data experts.

Why is my Validate always succeeding?!

Hi

XmlTextReader reader = new XmlTextReader("Accounts.xsd");
XmlSchema schema = XmlSchema.Read(reader, null);
schema.Compile(null);

XmlDocument d = new XmlDocument();
d.LoadXml("<ThisShouldNotValidate/>");
d.Schemas.Add(schema);
d.Validate(null);

I'm just nulling the event handlers for the moment so exceptions would
be thrown ... but they're not, in particular in the
XmlDocument.Validate which is what I'd expect!

So, what have I done that's silly then?

Here's the schema, which compiles fine (as you can see, I was having a
play with xs:include and types):

Accounts.xsd

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:include schemaLocation="Account.xsd"/>

<xs:complexType name="AccountT">
<xs:attribute name = "DateOpened" type="xs:date" use="required"/>
<xs:attribute name = "Name" type ="xs:string" use="required"/>
<xs:attribute name = "Type" type="AccountType" use ="required"/>
</xs:complexType>

<xs:element name ="Account" type="AccountT"/>

<xs:element name="Accounts">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element ref = "Account"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Account.xsd

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="AccountType">
<xs:restriction base="xs:string">
<xs:enumeration value="Cheque"/>
<xs:enumeration value="Savings"/>
<xs:enumeration value="Credit"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

Help very much appreciated to spot the obviously silly error.

Emma

Sep 10 '06 #1
1 1447
em**************@fastmail.fm wrote:
Hi

XmlTextReader reader = new XmlTextReader("Accounts.xsd");
XmlSchema schema = XmlSchema.Read(reader, null);
schema.Compile(null);

XmlDocument d = new XmlDocument();
d.LoadXml("<ThisShouldNotValidate/>");
d.Schemas.Add(schema);
d.Validate(null);

I'm just nulling the event handlers for the moment so exceptions would
be thrown ... but they're not, in particular in the
XmlDocument.Validate which is what I'd expect!

So, what have I done that's silly then?

Here's the schema, which compiles fine (as you can see, I was having a
play with xs:include and types):

Accounts.xsd

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:include schemaLocation="Account.xsd"/>

<xs:complexType name="AccountT">
<xs:attribute name = "DateOpened" type="xs:date" use="required"/>
<xs:attribute name = "Name" type ="xs:string" use="required"/>
<xs:attribute name = "Type" type="AccountType" use ="required"/>
</xs:complexType>

<xs:element name ="Account" type="AccountT"/>

<xs:element name="Accounts">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element ref = "Account"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Account.xsd

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="AccountType">
<xs:restriction base="xs:string">
<xs:enumeration value="Cheque"/>
<xs:enumeration value="Savings"/>
<xs:enumeration value="Credit"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

Help very much appreciated to spot the obviously silly error.

Emma
Has anyone had any ideas for me? It must be something silly but I can't
work it out.

Thanks

Emma

Sep 20 '06 #2

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

Similar topics

5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
0
by: Marina | last post by:
Let's say a user control has a bunch of textboxes. At some point the user control calls Validate to make sure all input is processed. The Validating event is fired, and if the input was invalid,...
26
by: webrod | last post by:
Hi, I have some php pages with a lot of HTML code. I am looking for a HTML validator tool (like TIDY). TIDY is not good enough with PHP tags (it removes a lot of php code). Do you have any...
2
by: embz | last post by:
this post concerns three pages. 1. this page: http://www.katherine-designs.com/sendemail.php i get the following errors: a lot of it seems to deal with the PHP code i inserted to the page....
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.