[Home] [By Thread] [By Date] [Recent Entries]
Hi Eddie,
You are correct. This schema is invalid, both for the reason you describe,
and also because any attribute that exists in a restriction must be an
attribute of the base type.
> > <xs:element name="myOuter">
> > <xs:complexType>
> > <xs:complexContent>
> > <xs:restriction base="xs:string">
> > <xs:attribute name="color" type="xs:string"/>
> > </xs:restriction>
> > </xs:complexContent>
> > </xs:complexType>
> > </xs:element>
Adding an attribute is always considered an extension. The only time you
would declare an attribute in a restriction would be to restrict an
attribute that is already part of the base type. This might be to restrict
the attribute's type, to make it required instead of optional, or to add a
default or fixed value. A valid example:
<xs:complexType name="base">
<xs:sequence>
<xs:element name="child"/>
</xs:sequence>
<xs:attribute name="attr1" type="xs:integer"/>
</xs:complexType>
<xs:complexType name="derived">
<xs:complexContent>
<xs:restriction base="base">
<xs:attribute name="attr1" type="xs:short" use="required"
default="1"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
In the other example, xs:string does not already have a "color" attribute,
so it is not valid.
Hope that helps,
Priscilla
-----------------------------------------------------------
Priscilla Walmsley priscilla@w...
Vitria Technology http://www.vitria.com
Author, Definitive XML Schema (Prentice Hall, Dec. 2001)
-----------------------------------------------------------
|

Cart



