提交 3df62f08 编写于 作者: A Atsushi Eno

Fix bug #661400 - fix complicated namespace resolution issue.

Namespaces in nested external schemas have to be validated against
immediately-containing schema. If there is a schema A with urn:x
targetNamespace imports a schema B with urn:y targetNamespace which
in turn includes another schema C, then C must be validated its namespace
against B, not A.
上级 14f4fbe9
......@@ -92,6 +92,7 @@ namespace System.Xml.Schema
groups = new XmlSchemaObjectTable();
notations = new XmlSchemaObjectTable();
schemaTypes = new XmlSchemaObjectTable();
compilationItems = new XmlSchemaObjectCollection ();
}
#region Properties
......@@ -360,7 +361,6 @@ namespace System.Xml.Schema
// Compile the content of this schema
compilationItems = new XmlSchemaObjectCollection ();
for (int i = 0; i < Items.Count; i++) {
compilationItems.Add (Items [i]);
}
......@@ -574,7 +574,7 @@ namespace System.Xml.Schema
} else if (includedSchema != null) {
if (TargetNamespace == null &&
includedSchema.TargetNamespace != null) {
error (handler, "Target namespace is required to include a schema which has its own target namespace");
includedSchema.error (handler, String.Format ("On {0} element, targetNamespace is required to include a schema which has its own target namespace", ext.GetType ().Name));
return;
}
else if (TargetNamespace != null &&
......@@ -591,11 +591,13 @@ namespace System.Xml.Schema
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, col);
// if (ext.Schema != null)
// AddExternalComponentsTo (ext.Schema, items);
foreach (XmlSchemaObject obj in s.Items)
s.ProcessExternal (handler, handledUris, resolver, ext, col);
foreach (XmlSchemaObject obj in s.compilationItems)
items.Add (obj);
// Items might be already resolved (recursive schema imports), or might not be (other cases), so we add items only when appropriate here. (duplicate check is anyways done elsewhere)
foreach (XmlSchemaObject obj in s.Items)
if (!items.Contains (obj))
items.Add (obj);
}
internal bool IsNamespaceAbsent (string ns)
......
......@@ -627,5 +627,12 @@ namespace MonoTests.System.Xml
while (reader.Read()) {}
}
#endif
[Test]
public void TestImportSchemaThatIncludesAnother ()
{
XmlSchema xs = GetSchema ("Test/XmlFiles/xsd/importNamespaceTest2.xsd");
xs.Compile (null);
}
}
}
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:y"
xmlns="urn:y">
<xs:element name="foo" />
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:x"
xmlns="urn:x" xmlns:y="urn:y">
<xs:import namespace="urn:y" schemaLocation="importedNamespace2.xsd" />
<xs:element name="foo" type="y:foo" />
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:y"
xmlns="urn:y" xmlns:x="urn:x" />
<xs:include schemaLocation="includedNamespace2.xsd" />
</xs:schema>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册