Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML NET4.5
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 .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 6:31am
Comments
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 OriginalGriff 245
1 Kamal Rocks 184
2 Sergey Alexandrovich Kryukov 175
3 BillWoodruff 173
4 PIEBALDconsult 160
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
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