Extending and adding attributes

This should cover W3C XML Schema, Relax NG and DTD related problems.
ahundiak
Posts: 7
Joined: Wed Mar 23, 2005 8:50 pm

Extending and adding attributes

Post by ahundiak » Wed Mar 23, 2005 8:58 pm

I am trying to extend a complex type and add some additional attributes.

<xs:complexType name="EntityType" abstract="true">
<xs:attribute name="id" type="xs:ID" use="optional"/>
<xs:attribute name="href" type="xs:anyURI" use="optional"/>
</xs:complexType>

<xs:complexType name="EdoType">

<xs:complexContent >
<xs:extension base="EntityType"/>
</xs:complexContent>

<xs:attribute name="X-href" type="xs:anyURI"/>
</xs:complexType>

Oxygen complains about the attribute being invalid or misplaced.

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Thu Mar 24, 2005 2:29 pm

Hi,

That is a basic error. If you use complexContent as a child if complexType you cannot have other elements following complexContent. You should place the attribute inside the xs:extension element as below:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="EntityType" abstract="true">
<xs:attribute name="id" type="xs:ID" use="optional"/>
<xs:attribute name="href" type="xs:anyURI" use="optional"/>
</xs:complexType>

<xs:complexType name="EdoType">
<xs:complexContent >
<xs:extension base="EntityType">
<xs:attribute name="X-href" type="xs:anyURI"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>

</xs:schema>
Best Regards,
George

ahundiak
Posts: 7
Joined: Wed Mar 23, 2005 8:50 pm

Post by ahundiak » Mon Mar 28, 2005 5:40 pm

Thanks a bunch. That makes sense.

Post Reply