Why XmlSchemaSet explicitely sets targetNamespace to chameleon schemas

Unanswered Why XmlSchemaSet explicitely sets targetNamespace to chameleon schemas

  • Wednesday, February 13, 2013 4:15 PM
     
      Has Code

    Hi everybody. 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?



All Replies

  • Thursday, February 14, 2013 6:13 PM
     
     
    In my view for validation purposes the included schema takes on the target namespace of the including schema and that is reflected in the schema object model.

    MVP Data Platform Development My blog