Click here to Skip to main content
12,952,792 members (38,105 online)
Rate this:
Please Sign up or sign in to vote.
See more:
For example, I have 2 Xml schemas:
<xsd:schema xmlns:xsd="" xmlns="test" targetNamespace="test">
    <xsd:include schemaLocation="b.xsd" />

<xsd:schema xmlns:xsd="">
    <xsd:simpleType name="testType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="test"/>
    <xsd:element name="test" type="testType"/>

Second schema does not have targetNamespace and used as a chameleon schema.
I am trying to pre-load these schemas using .Net 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?
Posted 13-Feb-13 5:31am
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,289
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,900

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100