[TestFixture]
public class XmlSchemaValidatorTests
{
+ void Validate (string xml, string xsd)
+ {
+ XmlSchema schema = XmlSchema.Read (new StringReader (xsd), null);
+ XmlReaderSettings settings = new XmlReaderSettings ();
+ settings.ValidationType = ValidationType.Schema;
+ settings.Schemas.Add (schema);
+ XmlReader reader = XmlReader.Create (new StringReader (xml), settings);
+ while (reader.Read ())
+ ;
+ }
+
[Test]
public void XsdAnyToSkipAttributeValidation ()
{
</xs:complexType>
</xs:element>
</xs:schema>";
+ string xml = @"<myDoc foo='12' bar='January 1st 1900'/>";
+ Validate (xml, xsd);
+ }
- XmlSchema schema = XmlSchema.Read (new StringReader (xsd), null);
- XmlReaderSettings settings = new XmlReaderSettings ();
- settings.ValidationType = ValidationType.Schema;
- settings.Schemas.Add (schema);
- XmlReader reader = XmlReader.Create (new StringReader (@"<myDoc foo='12' bar='January 1st 1900'/>"), settings);
- while (reader.Read ())
- ;
+ [Test]
+ public void Bug469713 ()
+ {
+ string xsd = @"<xs:schema elementFormDefault='qualified' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+ <xs:element name='Message'>
+ <xs:complexType>
+ <xs:all>
+ <xs:element name='MyDateTime' nillable='true' type='xs:dateTime' />
+ </xs:all>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>";
+ string xml = @"<Message xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='test.xsd'>
+ <MyDateTime xsi:nil='true'></MyDateTime>
+</Message>";
+ Validate (xml, xsd);
+ }
+
+ [Test]
+ public void Bug496192_496205 ()
+ {
+ using (var xmlr = new StreamReader ("Test/XmlFiles/496192.xml"))
+ using (var xsdr = new StreamReader ("Test/XmlFiles/496192.xsd"))
+ Validate (xmlr.ReadToEnd (), xsdr.ReadToEnd ());
+ }
+
+ [Test]
+ public void Bug501666 ()
+ {
+ string xsd = @"
+ <xs:schema id='Settings'
+ targetNamespace='foo'
+ xmlns='foo'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+
+ <xs:element name='Settings' type='Settings'/>
+
+ <xs:complexType name='Settings'>
+ <xs:attribute name='port' type='PortNumber' use='required'/>
+ </xs:complexType>
+
+ <xs:simpleType name='PortNumber'>
+ <xs:restriction base='xs:positiveInteger'>
+ <xs:minInclusive value='1'/>
+ <xs:maxInclusive value='65535'/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:schema>";
+
+ string xml = @"<Settings port='1337' xmlns='foo'/>";
+
+ XmlDocument doc = new XmlDocument ();
+ doc.LoadXml (xml);
+ doc.Schemas.Add (XmlSchema.Read (XmlReader.Create (new StringReader (xsd)), null));
+ doc.Validate (null);
+ }
+
+ public void Bug502251 ()
+ {
+ string xsd = @"
+ <xs:schema id='foo' targetNamespace='foo'
+ elementFormDefault='qualified'
+ xmlns='foo'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+
+ <xs:group name='LayoutElementTypes'>
+ <xs:choice>
+ <xs:element name='Rows' type='Rows' />
+ <xs:element name='Conditional' type='Conditional' />
+ </xs:choice>
+ </xs:group>
+
+ <xs:complexType name='Element' abstract='true'>
+ <xs:attribute name='id' type='xs:ID' use='optional'/>
+ </xs:complexType>
+
+ <xs:complexType name='SingleChildElement' abstract='true'>
+ <xs:complexContent>
+ <xs:extension base='Element'>
+ <xs:group ref='LayoutElementTypes' minOccurs='1' maxOccurs='1' />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name='Rows'>
+ <xs:complexContent>
+ <xs:extension base='Element'>
+ <xs:sequence minOccurs='1' maxOccurs='unbounded'>
+ <xs:element name='Row' type='Row' />
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name='Row'>
+ <xs:complexContent>
+ <xs:extension base='SingleChildElement'>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name='Conditional'>
+ <xs:complexContent>
+ <xs:extension base='Element'>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name='Layout'>
+ <xs:complexContent>
+ <xs:extension base='SingleChildElement'>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name='Layout' type='Layout' />
+</xs:schema>";
+
+ XmlDocument doc = new XmlDocument ();
+ doc.LoadXml (@"<Layout xmlns='foo'>
+ <Rows>
+ <Row><Conditional/></Row>
+ </Rows>
+</Layout>");
+
+ XmlSchema schema = XmlSchema.Read (XmlReader.Create (new StringReader (xsd)), null);
+
+ doc.Schemas.Add (schema);
+ doc.Validate (null);
+ }
+
+ [Test]
+ public void Bug557452 ()
+ {
+ string xsd = @"
+ <xs:schema id='Settings'
+ targetNamespace='foo'
+ xmlns='foo'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+
+ <xs:element name='Settings' type='Settings'/>
+
+ <xs:complexType name='Settings'>
+ <xs:attribute name='port' type='PortNumber' use='required'/>
+ </xs:complexType>
+
+ <xs:simpleType name='PortNumber'>
+ <xs:restriction base='xs:decimal'>
+ <xs:minInclusive value='1'/>
+ <xs:maxInclusive value='65535'/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:schema>";
+
+ string xml = @"<Settings port='1337' xmlns='foo'/>";
+
+ XmlDocument doc = new XmlDocument ();
+ doc.LoadXml (xml);
+ doc.Schemas.Add (XmlSchema.Read (XmlReader.Create (new StringReader (xsd)), null));
+ doc.Validate (null);
+ }
+
+ [Test]
+ public void Bug584664 ()
+ {
+ Validate (File.ReadAllText ("Test/XmlFiles/xsd/584664a.xml"), File.ReadAllText ("Test/XmlFiles/xsd/584664a.xsd"));
+ Validate (File.ReadAllText ("Test/XmlFiles/xsd/584664b.xml"), File.ReadAllText ("Test/XmlFiles/xsd/584664b.xsd"));
}
}
}