2008-02-19 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 19 Feb 2008 15:59:12 +0000 (15:59 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 19 Feb 2008 15:59:12 +0000 (15:59 -0000)
* XmlSchema.cs : Do recursively process xs:include inside included
  schemas. Fixed bug #361818.

* XmlSchemaTests.cs: added test for bug #361818.

* 361818.xsd, 361818-2.xsd, 361818-3.xsd : new test files.

* Makefile : extra distfiles (361818*.xsd).

svn path=/trunk/mcs/; revision=96159

mcs/class/System.XML/ChangeLog
mcs/class/System.XML/Makefile
mcs/class/System.XML/System.Xml.Schema/ChangeLog
mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs
mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog
mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs
mcs/class/System.XML/Test/XmlFiles/xsd/361818-2.xsd [new file with mode: 0644]
mcs/class/System.XML/Test/XmlFiles/xsd/361818-3.xsd [new file with mode: 0644]
mcs/class/System.XML/Test/XmlFiles/xsd/361818.xsd [new file with mode: 0644]
mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog

index df4b77ee0e3756b829c75b7ca0094778e934ccfe..046aa5445b36e03e7c5f8bff85033dabaf750039 100644 (file)
@@ -1,3 +1,7 @@
+2008-02-19  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * Makefile : extra distfiles (361818*.xsd).
+
 2008-02-19  Atsushi Enomoto  <atsushi@ximian.com>
 
        * System.Xml_test.dll.sources: added XmlSchemasTests.cs.
index 6ce3c438f643820c35308d9b088832ac6851a5d9..ab94431399ccde921b62643149c6019c0a2e0215 100644 (file)
@@ -74,6 +74,9 @@ EXTRA_DISTFILES = \
        Test/XmlFiles/xsd/datatypesTest.xsd \
        Test/XmlFiles/xsd/336625.xsd    \
        Test/XmlFiles/xsd/358408.xsd    \
+       Test/XmlFiles/xsd/361818.xsd    \
+       Test/XmlFiles/xsd/361818-2.xsd  \
+       Test/XmlFiles/xsd/361818-3.xsd  \
        Test/XmlFiles/xsd/77687.xsd     \
        Test/XmlFiles/xsd/77687inc.xsd  \
        Test/XmlFiles/xsd/78985.xml     \
index 37c4f5ad3ccf829c0e90bc53b826ceed735f4ad6..95c819e328a9e3f280248f8bc89962012d6afa07 100644 (file)
@@ -1,3 +1,8 @@
+2008-02-19  Atsushi Enomoto <atsushi@ximian.com>
+
+       * XmlSchema.cs : Do recursively process xs:include inside included
+         schemas. Fixed bug #361818.
+
 2008-02-19  Atsushi Enomoto <atsushi@ximian.com>
 
        * XmlSchemaAny.cs : block extra compilation in anyTypeContent.
index a9d8e74294ee5ff9645b2c9d642f9998d14292bf..66f2d7235543d3a96179e90d48ff68f9324615aa 100644 (file)
@@ -367,93 +367,8 @@ namespace System.Xml.Schema
 
                        // First, we run into inclusion schemas to collect 
                        // compilation target items into compiledItems.
-                       for (int i = 0; i < Includes.Count; i++) {
-                               XmlSchemaExternal ext = Includes [i] as XmlSchemaExternal;
-                               if (ext == null) {
-                                       error (handler, String.Format ("Object of Type {0} is not valid in Includes Property of XmlSchema", Includes [i].GetType().Name));
-                                       continue;
-                               }
-
-                               if (ext.SchemaLocation == null) 
-                                       continue;
-
-                               Stream stream = null;
-                               string url = null;
-                               if (resolver != null) {
-                                       url = GetResolvedUri (resolver, ext.SchemaLocation);
-                                       if (handledUris.Contains (url))
-                                               // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
-                                               continue;
-                                       handledUris.Add (url, url);
-                                       try {
-                                               stream = resolver.GetEntity (new Uri (url), null, typeof (Stream)) as Stream;
-                                       } catch (Exception) {
-                                       // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.
-                                               warn (handler, "Could not resolve schema location URI: " + url);
-                                               stream = null;
-                                       }
-                               }
-
-                               // Process redefinition children in advance.
-                               XmlSchemaRedefine redefine = Includes [i] as XmlSchemaRedefine;
-                               if (redefine != null) {
-                                       for (int j = 0; j < redefine.Items.Count; j++) {
-                                               XmlSchemaObject redefinedObj = redefine.Items [j];
-                                               redefinedObj.isRedefinedComponent = true;
-                                               redefinedObj.isRedefineChild = true;
-                                               if (redefinedObj is XmlSchemaType ||
-                                                       redefinedObj is XmlSchemaGroup ||
-                                                       redefinedObj is XmlSchemaAttributeGroup)
-                                                       compilationItems.Add (redefinedObj);
-                                               else
-                                                       error (handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
-                                       }
-                               }
-
-                               XmlSchema includedSchema = null;
-                               if (stream == null) {
-                                       // It is missing schema components.
-                                       missedSubComponents = true;
-                                       continue;
-                               } else {
-                                       XmlTextReader xtr = null;
-                                       try {
-                                               xtr = new XmlTextReader (url, stream, nameTable);
-                                               includedSchema = XmlSchema.Read (xtr, handler);
-                                       } finally {
-                                               if (xtr != null)
-                                                       xtr.Close ();
-                                       }
-                                       includedSchema.schemas = schemas;
-                               }
-                               includedSchema.SetParent ();
-                               ext.Schema = includedSchema;
-
-                               // Set - actual - target namespace for the included schema * before compilation*.
-                               XmlSchemaImport import = ext as XmlSchemaImport;
-                               if (import != null) {
-                                       if (TargetNamespace == includedSchema.TargetNamespace) {
-                                               error (handler, "Target namespace must be different from that of included schema.");
-                                               continue;
-                                       } else if (includedSchema.TargetNamespace != import.Namespace) {
-                                               error (handler, "Attribute namespace and its importing schema's target namespace must be the same.");
-                                               continue;
-                                       }
-                               } else {
-                                       if (TargetNamespace == null && 
-                                               includedSchema.TargetNamespace != null) {
-                                               error (handler, "Target namespace is required to include a schema which has its own target namespace");
-                                               continue;
-                                       }
-                                       else if (TargetNamespace != null && 
-                                               includedSchema.TargetNamespace == null)
-                                               includedSchema.TargetNamespace = TargetNamespace;
-                               }
-
-                               // Do not compile included schema here.
-
-                               AddExternalComponentsTo (includedSchema, compilationItems);
-                       }
+                       for (int i = 0; i < Includes.Count; i++)
+                               ProcessExternal (handler, handledUris, resolver, Includes [i] as XmlSchemaExternal);
 
                        // Compilation phase.
                        // At least each Compile() must give unique (qualified) name for each component.
@@ -557,11 +472,102 @@ namespace System.Xml.Schema
                        return abs != null ? abs.ToString () : String.Empty;
                }
 
-               void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items)
+               void ProcessExternal (ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaExternal ext)
+               {
+                       if (ext == null) {
+                               error (handler, String.Format ("Object of Type {0} is not valid in Includes Property of XmlSchema", ext.GetType().Name));
+                               return;
+                       }
+
+                       if (ext.SchemaLocation == null) 
+                               return;
+//                     if (ext.Schema != null) // already read
+//                             return;
+
+                       Stream stream = null;
+                       string url = null;
+                       if (resolver != null) {
+                               url = GetResolvedUri (resolver, ext.SchemaLocation);
+                               if (handledUris.Contains (url))
+                                       // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
+                                       return;
+                               handledUris.Add (url, url);
+                               try {
+                                       stream = resolver.GetEntity (new Uri (url), null, typeof (Stream)) as Stream;
+                               } catch (Exception) {
+                               // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.
+                                       warn (handler, "Could not resolve schema location URI: " + url);
+                                       stream = null;
+                               }
+                       }
+
+                       // Process redefinition children in advance.
+                       XmlSchemaRedefine redefine = ext as XmlSchemaRedefine;
+                       if (redefine != null) {
+                               for (int j = 0; j < redefine.Items.Count; j++) {
+                                       XmlSchemaObject redefinedObj = redefine.Items [j];
+                                       redefinedObj.isRedefinedComponent = true;
+                                       redefinedObj.isRedefineChild = true;
+                                       if (redefinedObj is XmlSchemaType ||
+                                               redefinedObj is XmlSchemaGroup ||
+                                               redefinedObj is XmlSchemaAttributeGroup)
+                                               compilationItems.Add (redefinedObj);
+                                       else
+                                               error (handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
+                               }
+                       }
+
+                       XmlSchema includedSchema = null;
+                       if (stream == null) {
+                               // It is missing schema components.
+                               missedSubComponents = true;
+                               return;
+                       } else {
+                               XmlTextReader xtr = null;
+                               try {
+                                       xtr = new XmlTextReader (url, stream, nameTable);
+                                       includedSchema = XmlSchema.Read (xtr, handler);
+                               } finally {
+                                       if (xtr != null)
+                                               xtr.Close ();
+                               }
+                               includedSchema.schemas = schemas;
+                       }
+                       includedSchema.SetParent ();
+                       ext.Schema = includedSchema;
+
+                       // Set - actual - target namespace for the included schema * before compilation*.
+                       XmlSchemaImport import = ext as XmlSchemaImport;
+                       if (import != null) {
+                               if (TargetNamespace == includedSchema.TargetNamespace) {
+                                       error (handler, "Target namespace must be different from that of included schema.");
+                                       return;
+                               } else if (includedSchema.TargetNamespace != import.Namespace) {
+                                       error (handler, "Attribute namespace and its importing schema's target namespace must be the same.");
+                                       return;
+                               }
+                       } else {
+                               if (TargetNamespace == null && 
+                                       includedSchema.TargetNamespace != null) {
+                                       error (handler, "Target namespace is required to include a schema which has its own target namespace");
+                                       return;
+                               }
+                               else if (TargetNamespace != null && 
+                                       includedSchema.TargetNamespace == null)
+                                       includedSchema.TargetNamespace = TargetNamespace;
+                       }
+
+                       // Do not compile included schema here.
+
+                       AddExternalComponentsTo (includedSchema, compilationItems, handler, handledUris, resolver);
+               }
+
+               void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver)
                {
                        foreach (XmlSchemaExternal ext in s.Includes)
-                               if (ext.Schema != null)
-                                       AddExternalComponentsTo (ext.Schema, items);
+                               ProcessExternal (handler, handledUris, resolver, ext);
+//                             if (ext.Schema != null)
+//                                     AddExternalComponentsTo (ext.Schema, items);
                        foreach (XmlSchemaObject obj in s.Items)
                                items.Add (obj);
                }
index c5e9e09030daac77ec1d54085359c3f804526b72..e44b5c90263583088fc11b4095a1f52566d80368 100644 (file)
@@ -1,3 +1,7 @@
+2008-02-19  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XmlSchemaTests.cs: added test for bug #361818.
+
 2008-02-04  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlSchemaValidatorTests.cs : new. Test for bug #358408.
index 403df773ab9fa538210777d95b78fc79370ba3af..aa3cc3638ac4595c25219b1ecc4c0d89f8bd8c64 100644 (file)
@@ -406,5 +406,17 @@ namespace MonoTests.System.Xml
                        while (!vr.EOF)
                                vr.Read ();
                }
+
+               [Test]
+               public void ThreeLevelNestedInclusion ()
+               {
+                       XmlTextReader r = new XmlTextReader ("Test/XmlFiles/xsd/361818.xsd");
+                       try {
+                               XmlSchema xs = XmlSchema.Read (r, null);
+                               xs.Compile (null);
+                       } finally {
+                               r.Close ();
+                       }
+               }
        }
 }
diff --git a/mcs/class/System.XML/Test/XmlFiles/xsd/361818-2.xsd b/mcs/class/System.XML/Test/XmlFiles/xsd/361818-2.xsd
new file mode 100644 (file)
index 0000000..3dad2f9
--- /dev/null
@@ -0,0 +1,8 @@
+<xs:schema targetNamespace="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/" xmlns="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">\r
+       <xs:include schemaLocation="361818-3.xsd"/>\r
+       <xs:group name="Letters">\r
+               <xs:choice>\r
+                       <xs:element ref="HospitalReferral"/>\r
+               </xs:choice>\r
+       </xs:group>\r
+</xs:schema>\r
diff --git a/mcs/class/System.XML/Test/XmlFiles/xsd/361818-3.xsd b/mcs/class/System.XML/Test/XmlFiles/xsd/361818-3.xsd
new file mode 100644 (file)
index 0000000..afa3696
--- /dev/null
@@ -0,0 +1,3 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/" targetNamespace="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/" elementFormDefault="qualified" attributeFormDefault="unqualified">\r
+  <xs:element name="HospitalReferral" />\r
+</xs:schema>\r
diff --git a/mcs/class/System.XML/Test/XmlFiles/xsd/361818.xsd b/mcs/class/System.XML/Test/XmlFiles/xsd/361818.xsd
new file mode 100644 (file)
index 0000000..7295498
--- /dev/null
@@ -0,0 +1,3 @@
+<xs:schema targetNamespace="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/" xmlns="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">\r
+       <xs:include schemaLocation="361818-2.xsd"/>\r
+</xs:schema>\r
index c454412f1435d2a9890badac3ef23305d6899036..c7ba6c6191941b785192bbfdd0d65588e5a15569 100644 (file)
@@ -1,3 +1,7 @@
+2008-02-19  Atsushi Enomoto <atsushi@ximian.com>
+
+       * 361818.xsd, 361818-2.xsd, 361818-3.xsd : new test files.
+
 2008-02-04  Atsushi Enomoto <atsushi@ximian.com>
 
        * 358408.xsd : new test file.