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