Hello all,
I am having a problem with extending complex types. I have a simple
base schema (FooBar.xsd) which defines XML documents of the following
form:
<Foo FooAttribute1="aaa">
<Bar BarAttribute1="xxx"/>
</Foo>
I'm trying to write a schema (ExtendedFooBar.xsd) which includes
FooBar.xsd to add one new attribute (each) to <Foo> and <Bar>.
Documents adhering to this schema should look like:
<Foo FooAttribute1="aaa" FooAttribute2="bbb">
<Bar BarAttribute1="xxx" BarAttribute2="yyy"/>
</Foo>
I can get ExtendedFooBar.xsd to validate, but XML which adheres to it
doesn't recognize the new Bar attribute. In other words, valid XML
documents are of the following form:
<Foo FooAttribute1="aaa" FooAttribute2="bbb">
<!-- Note the missing BarAttribute2 -->
<Bar BarAttribute1="xxx"/>
</Foo>
Naively, I thought that by including the base schema in the extended
one, references to 'Bar' would be satisfied by the definition in the
extended schema. This seems to be incorrect.
Here's the schema XML for the two files:
--- FooBar.xsd ---
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified" >
<xs:complexType name="FooType">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="Bar"/>
</xs:sequence>
<xs:attribute name="FooAttribute1" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="BarType">
<xs:attribute name="BarAttribute1" type="xs:string" use="required"/>
</xs:complexType>
<xs:element name="Bar" type="BarType"/>
<xs:element name="Foo" type="FooType"/>
</xs:schema>
--- ExtendedFooBar.xsd ---
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="BaseFooBar.xsd"/>
<xs:complexType name="ExtendedBarType">
<xs:complexContent>
<xs:extension base="BarType">
<xs:attribute name="BarAttribute2" type="xs:string"
use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="ExtendedFooType">
<xs:complexContent>
<xs:extension base="FooType">
<xs:attribute name="FooAttribute2" type="xs:string"
use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Bar" type="ExtendedBarType"/>
<xs:element name="Foo" type="ExtendedFooType"/>
</xs:schema>
Any help would be appreciated. I've been scouring the web and my books
for a few hours on this one.
Thanks,
Brian