From: Atsushi Eno Date: Fri, 6 Jun 2008 10:07:22 +0000 (-0000) Subject: 2008-06-06 Atsushi Enomoto X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=13bc5269f3613059954d5dc3ac60ab08e39cc764;p=mono.git 2008-06-06 Atsushi Enomoto * XmlSchema.cs : fixed bug #397612, patch by James Fitzsimons. in ProcessExternal(), Make xs:import without schemaLocation work fine as if it were with schemaLocation. 2008-06-06 James Fitzsimons * XmlSchemaTests.cs: added test for bug #397612. * XmlSchemaAssertion.cs : make sure to close schema XmlReader. 2008-06-06 Atsushi Enomoto * importNamespaceTest.xsd, xsdimporttest.xml, importedNamespace.xsd: new test files. svn path=/trunk/mcs/; revision=105144 --- diff --git a/mcs/class/System.XML/System.Xml.Schema/ChangeLog b/mcs/class/System.XML/System.Xml.Schema/ChangeLog index e9123debcc7..cabc0d81685 100644 --- a/mcs/class/System.XML/System.Xml.Schema/ChangeLog +++ b/mcs/class/System.XML/System.Xml.Schema/ChangeLog @@ -1,3 +1,9 @@ +2008-06-06 Atsushi Enomoto + + * XmlSchema.cs : fixed bug #397612, patch by James Fitzsimons. + in ProcessExternal(), Make xs:import without schemaLocation work + fine as if it were with schemaLocation. + 2008-06-06 James Fitzsimons * XmlSchema.cs : Changed GetResolvedUri to return Uri in correct case diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs index b4dbed9c33c..9851f10c024 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs @@ -368,7 +368,7 @@ 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++) - ProcessExternal (handler, handledUris, resolver, Includes [i] as XmlSchemaExternal); + ProcessExternal (handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col); // Compilation phase. // At least each Compile() must give unique (qualified) name for each component. @@ -476,18 +476,21 @@ namespace System.Xml.Schema #endif } - void ProcessExternal (ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaExternal ext) + void ProcessExternal (ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaExternal ext, XmlSchemaSet col) { 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) + // The only case we want to handle where the SchemaLocation is null is if the external is an import. + XmlSchemaImport import = ext as XmlSchemaImport; + if (ext.SchemaLocation == null && import == null) return; -// if (ext.Schema != null) // already read -// return; - + + XmlSchema includedSchema = null; + if (ext.SchemaLocation != null) + { Stream stream = null; string url = null; if (resolver != null) { @@ -504,7 +507,7 @@ namespace System.Xml.Schema stream = null; } } - + // Process redefinition children in advance. XmlSchemaRedefine redefine = ext as XmlSchemaRedefine; if (redefine != null) { @@ -521,7 +524,6 @@ namespace System.Xml.Schema } } - XmlSchema includedSchema = null; if (stream == null) { // It is missing schema components. missedSubComponents = true; @@ -539,16 +541,35 @@ namespace System.Xml.Schema } 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; + if (ext.Schema == null && ext.SchemaLocation == null) { + // if a schema location wasn't specified, check the other schemas we have to see if one of those + // is a match. + foreach(XmlSchema schema in col.Schemas()) + { + if (schema.TargetNamespace == import.Namespace) + { + includedSchema = schema; + includedSchema.schemas = schemas; + includedSchema.SetParent (); + ext.Schema = includedSchema; + break; + } + } + // handle case where target namespace doesn't exist in schema collection - i.e can't find it at all + if (includedSchema == null) + return; + } else { + 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 && @@ -563,13 +584,14 @@ namespace System.Xml.Schema // Do not compile included schema here. - AddExternalComponentsTo (includedSchema, compilationItems, handler, handledUris, resolver); + AddExternalComponentsTo (includedSchema, compilationItems, handler, handledUris, resolver, col); } - void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver) + + void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaSet col) { foreach (XmlSchemaExternal ext in s.Includes) - ProcessExternal (handler, handledUris, resolver, ext); + ProcessExternal (handler, handledUris, resolver, ext, col); // if (ext.Schema != null) // AddExternalComponentsTo (ext.Schema, items); foreach (XmlSchemaObject obj in s.Items) diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog b/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog index c3bcc5c3242..50c29662ebd 100644 --- a/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog +++ b/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog @@ -1,3 +1,8 @@ +2008-06-06 James Fitzsimons + + * XmlSchemaTests.cs: added test for bug #397612. + * XmlSchemaAssertion.cs : make sure to close schema XmlReader. + 2008-06-06 James Fitzsimons * XmlSchemaTests.cs: added test to support change to diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaAssertion.cs b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaAssertion.cs index 2fe553dd744..7e55ed0ed77 100644 --- a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaAssertion.cs +++ b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaAssertion.cs @@ -20,7 +20,10 @@ namespace MonoTests.System.Xml { protected XmlSchema GetSchema (string path) { - return XmlSchema.Read (new XmlTextReader (path), null); + XmlTextReader reader = new XmlTextReader (path); + XmlSchema schema = XmlSchema.Read (reader, null); + reader.Close (); + return schema; } protected XmlQualifiedName QName (string name, string ns) diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs index c58efe130db..a4f36651731 100644 --- a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs +++ b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs @@ -477,6 +477,23 @@ namespace MonoTests.System.Xml AssertEquals ("assembly://MyAssembly.Name/MyProjectNameSpace/objects.xsd", resolver.ReceivedUri.OriginalString); } + + [Test] + public void TestImportNoSchemaLocation() + { + XmlSchemaSet schemaSet = new XmlSchemaSet (); + schemaSet.Add (GetSchema ("Test/XmlFiles/xsd/importNamespaceTest.xsd")); + schemaSet.Add (GetSchema ("Test/XmlFiles/xsd/importedNamespace.xsd")); + + XmlReaderSettings settings = new XmlReaderSettings (); + settings.Schemas.Add (schemaSet); + settings.ValidationType = ValidationType.Schema; + + XmlReader reader = XmlReader.Create ("Test/XmlFiles/xsdimporttest.xml", settings); + + // Parse the file. + while (reader.Read()) {} + } #endif } } diff --git a/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog b/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog index 107eee79875..5ef02f4df1c 100644 --- a/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog +++ b/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog @@ -1,3 +1,8 @@ +2008-06-06 Atsushi Enomoto + + * importNamespaceTest.xsd, xsdimporttest.xml, importedNamespace.xsd: + new test files. + 2008-06-06 Atsushi Enomoto * resolveUriSchema.xsd : (actually I've incorrectly added it before diff --git a/mcs/class/System.XML/Test/XmlFiles/xsd/importNamespaceTest.xsd b/mcs/class/System.XML/Test/XmlFiles/xsd/importNamespaceTest.xsd new file mode 100644 index 00000000000..ab5c1e2da63 --- /dev/null +++ b/mcs/class/System.XML/Test/XmlFiles/xsd/importNamespaceTest.xsd @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mcs/class/System.XML/Test/XmlFiles/xsd/importedNamespace.xsd b/mcs/class/System.XML/Test/XmlFiles/xsd/importedNamespace.xsd new file mode 100644 index 00000000000..5c6f0aa22f2 --- /dev/null +++ b/mcs/class/System.XML/Test/XmlFiles/xsd/importedNamespace.xsd @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mcs/class/System.XML/Test/XmlFiles/xsd/xsdimporttest.xml b/mcs/class/System.XML/Test/XmlFiles/xsd/xsdimporttest.xml new file mode 100644 index 00000000000..7015479169a --- /dev/null +++ b/mcs/class/System.XML/Test/XmlFiles/xsd/xsdimporttest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + +