Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
For example, I have 2 Xml schemas:
a.xsd
XML
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="test" targetNamespace="test">
    <xsd:include schemaLocation="b.xsd" />
</xsd:schema>`

b.xsd
XML
<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 .Net XmlSchemaSet:

C#
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?
Posted
Comments
Thomas Duwe 13-Feb-13 12:15pm    
You didn't set a targetnamespace in b.xsd, so the targetnamespace from a.xsd is used.
Try to give b.xsd a different targetnamespace than a.xsd and the b.xsd xmlschema should have a different one.
Newermore 13-Feb-13 17:57pm    
I dont want to make any changes in original schemas. Here is the expecting behaviour:
I open b.xsd using some api(XmlSchemaSet used for this) , serealize loaded schama objects to the custom binary format, deserealize data to xsd. After the last step i am expect that output xsd`s will be the same as original, but targetNamespace was added. A can manualy load schemas, but there are many worst cases, so i am loking for existing solution at first. Maybe schemaSet is a wrong choise.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900