users@jaxb.java.net

Changin the default value of an attribute when extending a complexType

From: Bjørn Hamre <bjorn.hamre_at_EIENDOMSINFO.NO>
Date: Fri, 21 Feb 2003 07:30:22 -0700

I have a problem changing the default value og an attribute that is inherited from complexType by method of extension.

I have a complexType, fooType, that has an attribute fooAttrib.
Several elements, here fooElem, will extend fooType (see example below).
I need to have each element that extends fooType to set a different default value for the attribute fooAttrib. If I specify an attribute in fooElem with the same name and correct default value, I get an error message saying:

"ct-props-correct.4: Error for type '#AnonType_fooElem'. Duplicate attribute uses with the same name and target namespace are specified. Name of duplicate attribute use is 'fooAttrib'"

How can I set/change the default value for an attribute inherited from a complexType? I need this attribute to be in the complexType fooType, it is not an option to declare it only each of the 'sub-classes' and not in fooType.

Does anyone know if this is possible to do and how to do it?
Regards
Bj?rn Hamre

(example below)

<xs:complexType name="fooType">
   <xs:sequence>
      <xs:element minOccurs="0" name="fooElem" type="xs:string"/>
   </xs:sequence>
   <xs:attribute name="fooAttrib" use="optional" type="xs:string" />
</xs:complexType>

<xs:element name="fooElem">
   <xs:complexType>
      <xs:complexContent>
         <xs:extension base="fooType">
            <xs:sequence>
               <xs:element name="bar" type="xs:string"/>
            </xs:sequence>
            <xs:attribute name="fooAttrib" type="xs:string" default="fa" />
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>
</xs:element>