* 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 <james.fitzsimons@gmail.com>
* XmlSchemaTests.cs: added test for bug #397612.
* XmlSchemaAssertion.cs : make sure to close schema XmlReader.
2008-06-06 Atsushi Enomoto <atsushi@ximian.com>
* importNamespaceTest.xsd, xsdimporttest.xml, importedNamespace.xsd:
new test files.
svn path=/trunk/mcs/; revision=105144
+2008-06-06 Atsushi Enomoto <atsushi@ximian.com>
+
+ * 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 <james.fitzsimons@gmail.com>
* XmlSchema.cs : Changed GetResolvedUri to return Uri in correct case
// 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.
#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) {
stream = null;
}
}
-
+
// Process redefinition children in advance.
XmlSchemaRedefine redefine = ext as XmlSchemaRedefine;
if (redefine != null) {
}
}
- XmlSchema includedSchema = null;
if (stream == null) {
// It is missing schema components.
missedSubComponents = true;
}
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 &&
// 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)
+2008-06-06 James Fitzsimons <james.fitzsimons@gmail.com>
+
+ * XmlSchemaTests.cs: added test for bug #397612.
+ * XmlSchemaAssertion.cs : make sure to close schema XmlReader.
+
2008-06-06 James Fitzsimons <james.fitzsimons@gmail.com>
* XmlSchemaTests.cs: added test to support change to
{
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)
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
}
}
+2008-06-06 Atsushi Enomoto <atsushi@ximian.com>
+
+ * importNamespaceTest.xsd, xsdimporttest.xml, importedNamespace.xsd:
+ new test files.
+
2008-06-06 Atsushi Enomoto <atsushi@ximian.com>
* resolveUriSchema.xsd : (actually I've incorrectly added it before
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ targetNamespace="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:objects="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+
+ <xs:import namespace="http://tempuri.org/importedNamespace.xsd" />
+
+ <xs:element name="root">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="feisty">
+ <xs:complexType>
+ <xs:group ref="objects:objectList" minOccurs="1" maxOccurs="unbounded"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ targetNamespace="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:objects="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+
+ <xs:import namespace="http://tempuri.org/importedNamespace.xsd" />
+
+ <xs:element name="root">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="feisty">
+ <xs:complexType>
+ <xs:group ref="objects:objectList" minOccurs="1" maxOccurs="unbounded"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ targetNamespace="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:objects="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+
+ <xs:import namespace="http://tempuri.org/importedNamespace.xsd" />
+
+ <xs:element name="root">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="feisty">
+ <xs:complexType>
+ <xs:group ref="objects:objectList" minOccurs="1" maxOccurs="unbounded"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ targetNamespace="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:objects="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+
+ <xs:import namespace="http://tempuri.org/importedNamespace.xsd" />
+
+ <xs:element name="root">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="feisty">
+ <xs:complexType>
+ <xs:group ref="objects:objectList" minOccurs="1" maxOccurs="unbounded"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ targetNamespace="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:objects="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+
+ <xs:import namespace="http://tempuri.org/importedNamespace.xsd" />
+
+ <xs:element name="root">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="feisty">
+ <xs:complexType>
+ <xs:group ref="objects:objectList" minOccurs="1" maxOccurs="unbounded"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importedNamespace.xsd"
+ targetNamespace="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+ <xs:group name="objectList">
+ <xs:sequence>
+ <xs:element name="description" type="xs:string" minOccurs="0"/>
+ </xs:sequence>
+ </xs:group>
+</xs:schema>
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importedNamespace.xsd"
+ targetNamespace="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+ <xs:group name="objectList">
+ <xs:sequence>
+ <xs:element name="description" type="xs:string" minOccurs="0"/>
+ </xs:sequence>
+ </xs:group>
+</xs:schema>
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importedNamespace.xsd"
+ targetNamespace="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+ <xs:group name="objectList">
+ <xs:sequence>
+ <xs:element name="description" type="xs:string" minOccurs="0"/>
+ </xs:sequence>
+ </xs:group>
+</xs:schema>
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importedNamespace.xsd"
+ targetNamespace="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+ <xs:group name="objectList">
+ <xs:sequence>
+ <xs:element name="description" type="xs:string" minOccurs="0"/>
+ </xs:sequence>
+ </xs:group>
+</xs:schema>
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://tempuri.org/importedNamespace.xsd"
+ targetNamespace="http://tempuri.org/importedNamespace.xsd"
+ elementFormDefault="qualified">
+ <xs:group name="objectList">
+ <xs:sequence>
+ <xs:element name="description" type="xs:string" minOccurs="0"/>
+ </xs:sequence>
+ </xs:group>
+</xs:schema>
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<root xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:obj="http://tempuri.org/importedNamespace.xsd">
+ <feisty/>
+</root>
+
+<?xml version="1.0" encoding="utf-8" ?>
+<root xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:obj="http://tempuri.org/importedNamespace.xsd">
+ <feisty/>
+</root>
+
+<?xml version="1.0" encoding="utf-8" ?>
+<root xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:obj="http://tempuri.org/importedNamespace.xsd">
+ <feisty/>
+</root>
+
+<?xml version="1.0" encoding="utf-8" ?>
+<root xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:obj="http://tempuri.org/importedNamespace.xsd">
+ <feisty/>
+</root>
+
+<?xml version="1.0" encoding="utf-8" ?>
+<root xmlns="http://tempuri.org/importNamespaceTest.xsd"
+ xmlns:obj="http://tempuri.org/importedNamespace.xsd">
+ <feisty/>
+</root>
+