//
// (C) 2004 Novell Inc.
//
-#if NET_2_0
using System;
using System.Collections;
using System.IO;
+using System.Text;
using System.Xml;
using System.Xml.Schema;
using NUnit.Framework;
ss.Compile ();
Assert.IsTrue (ss.IsCompiled, "#4");
ss.RemoveRecursive (s);
- Assert.IsTrue (ss.IsCompiled, "#5");
+ Assert.IsFalse (ss.IsCompiled, "#5");
}
[Test] // bug #77489
schemas.Add (XmlSchema.Read (new StringReader (schema2), null));
schemas.Compile ();
}
+
+ [Test]
+ public void ImportSubstitutionGroupDBR ()
+ {
+ // This bug happened when
+ // 1) a schema imports another schema,
+ // 2) there is a substitutionGroup which is involved in
+ // complexContent schema conformance check, and
+ // 3) the included schema is already added to XmlSchemaSet.
+ XmlSchemaSet xss = new XmlSchemaSet ();
+ xss.Add (null, "Test/XmlFiles/xsd/import-subst-dbr-base.xsd");
+ xss.Add (null, "Test/XmlFiles/xsd/import-subst-dbr-ext.xsd");
+ // should not result in lack of substitutionGroup
+ // (and conformance error as its result)
+ xss.Compile ();
+ }
+
+ [Test]
+ public void AddWithNullTargetNS () // bug #571650
+ {
+ var xsdraw = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'><xs:element name='foo' /></xs:schema>";
+ var schemas = new XmlSchemaSet ();
+ var xsd = schemas.Add ("", XmlReader.Create (new StringReader (xsdraw)));
+ Assert.IsNull (xsd.TargetNamespace, "#1");
+ }
+
+ [Test] // part of bug #670945
+ public void TwoSchemasInSameDocumentUri ()
+ {
+ string xsd1 = @"
+ <xs:schema
+ targetNamespace='http://www.onvif.org/ver10/schema'
+ elementFormDefault='qualified'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ xmlns:tt='http://www.onvif.org/ver10/schema'>
+
+ <xs:complexType name='SystemDateTime'>
+ <xs:sequence>
+ <xs:element name='foobar' type='xs:string' minOccurs='0' />
+ <xs:element name='Extension' type='tt:SystemDateTimeExtension' minOccurs='0'/>
+ </xs:sequence>
+ <!-- xs:anyAttribute processContents='lax'/ -->
+ </xs:complexType>
+
+ <xs:complexType name='SystemDateTimeExtension'>
+ <xs:sequence>
+ <xs:any namespace='##any' processContents='lax' minOccurs='0' maxOccurs='unbounded'/>
+ </xs:sequence>
+ </xs:complexType>
+
+ </xs:schema>";
+
+ string xsd2 = @"
+ <xs:schema
+ targetNamespace='http://www.onvif.org/ver10/device/wsdl'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ xmlns:tt='http://www.onvif.org/ver10/schema'
+ xmlns:tds='http://www.onvif.org/ver10/device/wsdl'
+ elementFormDefault='qualified'>
+ <xs:element name='GetSystemDateAndTime'>
+ <xs:complexType>
+ <xs:sequence/>
+
+ </xs:complexType>
+ </xs:element>
+ <xs:element name='GetSystemDateAndTimeResponse'>
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name='SystemDateAndTime' type='tt:SystemDateTime' />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:schema>";
+
+ var xss = new XmlSchemaSet ();
+ var xs1 = XmlSchema.Read (new StringReader (xsd1), null);
+ xs1.SourceUri = "http://localhost:8080/dummy.wsdl";
+ xs1.LineNumber = 5;
+ xss.Add (xs1);
+ var xs2 = XmlSchema.Read (new StringReader (xsd2), null);
+ xs2.SourceUri = "http://localhost:8080/dummy.wsdl";
+ xs2.LineNumber = 50;
+ xss.Add (xs2);
+ xss.Compile ();
+ Assert.IsNotNull (xss.GlobalElements [new XmlQualifiedName ("GetSystemDateAndTimeResponse", "http://www.onvif.org/ver10/device/wsdl")], "#1");
+ }
+
+ [Test] // bug #13716
+ public void ResolveSchemaUriUsingXmlResolver ()
+ {
+ var resolver = new Bug13716XmlResolver ();
+ string xml = "<people xmlns='testschema'><person name='Ian'><books><book>Clean Code</book></books></person></people>";
+ string ns = "testschema";
+ string xsdPath = "my.xsd";
+
+ var readerSettings = new XmlReaderSettings ();
+
+ //readerSettings.XmlResolver = resolver;
+ readerSettings.Schemas.XmlResolver = resolver;
+ readerSettings.Schemas.Add (ns, xsdPath);
+ readerSettings.ValidationType = ValidationType.Schema;
+
+ using (var xr = XmlReader.Create (new StringReader (xml), readerSettings))
+ {
+ while (!xr.EOF)
+ xr.Read ();
+ }
+ }
+
+ public class Bug13716XmlResolver : XmlUrlResolver
+ {
+ public override object GetEntity(Uri absoluteUri, string role, Type typeOfObjectToReturn)
+ {
+ string xsd = @"
+ <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='testschema'>
+ <xs:element name='people' />
+ </xs:schema>";
+ return new MemoryStream (Encoding.UTF8.GetBytes (xsd));
+ }
+ }
}
}
-#endif