Page 1 of 1

Swap attributeGroup in derivation

Posted: Wed Mar 01, 2006 12:54 pm
by alk
Hi,

is it possible to derive a complexType and in the derivation replace an attributeGroup of the parent by another attributeGroup??? ...oh, and if it is possible, how? TIA!

Regards
- Alex

Posted: Wed Mar 08, 2006 11:58 am
by george
Hi Alex,

The close yo can get is something like below. You can prohibit the attributes from the first group in a restriction assuming they are optional, otherwise you cannot prohibit them and then you can add other attributes in an extension:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:attributeGroup name="a1group">
<xs:attribute name="a1"/>
</xs:attributeGroup>

<xs:attributeGroup name="a2group">
<xs:attribute name="a2"/>
</xs:attributeGroup>

<xs:complexType name="parent">
<xs:attributeGroup ref="a1group"/>
</xs:complexType>


<xs:complexType name="childTmp">
<xs:complexContent>
<xs:restriction base="parent">
<xs:attribute name="a1" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="child">
<xs:complexContent>
<xs:extension base="childTmp">
<xs:attributeGroup ref="a2group"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="child" type="child"/>
</xs:schema>
In the above case child will contain only a2 as attribute - you can see this in the Model View diagram in oXygen, that presents the model of the parsed schema document.

Best Regards,
George

Posted: Mon Mar 13, 2006 3:15 pm
by alk
Hi George,

thanks for your answer. I found one more solution. It's possible to have the derivation in a separate file by using redefine with the "parent XSD". This way attributes can be left out or added at will. In the end it's not "attribute group swapping", but better than nothing...

Cheers
- Alex

Posted: Mon Mar 13, 2006 3:23 pm
by george
Hi Alex,

Just be careful as when you redefine all the references to that group are redefined.

Best Regards,
George