Click here to Skip to main content
11,803,019 members (78,569 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# XML .NET4.5
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 at 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 at 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
0 KrunalRohit 356
1 OriginalGriff 335
2 CPallini 270
3 F-ES Sitecore 270
4 Sergey Alexandrovich Kryukov 234
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,735
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2015
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