Swap attributeGroup in derivation

This should cover W3C XML Schema, Relax NG and DTD related problems.
alk
Posts: 32
Joined: Wed Jan 25, 2006 5:43 pm

Swap attributeGroup in derivation

Post by alk » Wed Mar 01, 2006 12:54 pm

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

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

Post by george » Wed Mar 08, 2006 11:58 am

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

alk
Posts: 32
Joined: Wed Jan 25, 2006 5:43 pm

Post by alk » Mon Mar 13, 2006 3:15 pm

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

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

Post by george » Mon Mar 13, 2006 3:23 pm

Hi Alex,

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

Best Regards,
George

Post Reply