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"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied" >
<xs:complexTy pe name="FooType">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="Bar"/>
</xs:sequence>
<xs:attribute name="FooAttrib ute1" type="xs:string " use="required"/>
</xs:complexType>
<xs:complexTy pe name="BarType">
<xs:attribute name="BarAttrib ute1" 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"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:include schemaLocation= "BaseFooBar.xsd "/>
<xs:complexTy pe name="ExtendedB arType">
<xs:complexCont ent>
<xs:extension base="BarType">
<xs:attribute name="BarAttrib ute2" type="xs:string "
use="required"/>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="ExtendedF ooType">
<xs:complexCont ent>
<xs:extension base="FooType">
<xs:attribute name="FooAttrib ute2" type="xs:string "
use="required"/>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>
<xs:element name="Bar" type="ExtendedB arType"/>
<xs:element name="Foo" type="ExtendedF ooType"/>
</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