Why XmlSchemaSet explicitely sets targetNamespace to chameleon schemas

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine

For example, I have 2 Xml schemas:

a.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="test" targetNamespace="test
<xsd:include schemaLocation="b.xsd" />
</xsd:schema>`
b.xsd:<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema
<xsd:simpleType name="testType
<xsd:restriction base="xsd:string
<xsd:enumeration value="test"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="test" type="testType"/>
</xsd:schema>

Second schema does not have targetNamespace and used as a chameleon schema.

I am trying to pre-load these schemas using XmlSchemaSet:
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(null, @"a.xsd");

foreach (XmlSchema schema in schemaSet.Schemas()) // foreach is used to simplify the example
{
Console.WriteLine("Target namespace: "schema.TargetNamespace); // "Target namespace: test"
XmlSchemaInclude include = (XmlSchemaInclude)schema.Includes[0];
Console.WriteLine("Include target namespace: " + include.Schema.TargetNamespace); // "Include target namespace: test"
}
But after I do it both schemas have "test" target namespace. I expect instantiated schema objects should be equal to source schemas, but it is not true for schema "b.xsd". Why it behaves so and is there any way to disable such a behavior?

View the full article
 
Back
Top