Greetings,
I am writing an application that uses an extendible XML file. in order
to validate that XML I use a main XSD and in additional - few more
extensions XSD's that uses the types in the main XSD as base types.
my clients can define their own XSD's extensions and use my generic
application to process their XML's.
The problem:
I use the same namespace in all of the XSD's ( both base and extensions
), the first time I load a Schema into the XmlSchemaCollection it works
fine, but on the next schemas , the XmlSchemaCollection just overwrite
the previous ( maybe because of the same namespace ) and I only remain
with the most previously schema loaded.
code:
string[] schemas = new string[2]{"SchemaA.xsd","SchemaB.xsd"};
for(int i=0 ;i< schemas.GetLength(0) ; i++)
{
XmlTextReader xsdReader =new XmlTextReader(schemas[i]);
XmlSchema schem = XmlSchema.Read(xsdReader ,new
ValidationEventHandler(SchemaHandler) );
collection.Add(schem);
}
SchemA.xsd :
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="MyOwnNS" elementFormDefault="qualified"
xmlns="MyOwnNS"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="BaseSchema.xsd"/>
<xs:complexType name="ExtendibleA_Type">
<xs:complexContent>
<xs:extension base="Base_Type">
<xs:sequence>
<xs:element name="blabla" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="ExtendibleA" substitutionGroup="BaseElement"
type="ExtendibleA_Type" />
</xs:schema>
SchemaB.xsd :
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="MyOwnNS" elementFormDefault="qualified"
xmlns="MyOwnNS"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="BaseSchema.xsd"/>
<xs:complexType name="ExtendibleB_Type">
<xs:complexContent>
<xs:extension base="Base_Type">
<xs:sequence>
<xs:element name="whiwhi" type="xs:integer" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="ExtendibleB" substitutionGroup="BaseElement"
type="ExtendibleB_Type" />
</xs:schema>
I didnt add the base schema but it has the same target namespace.
must I differ the schemas with different namespace's ?