Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The problem with substitutionGroups

Status
Not open for further replies.

Penguinpile

Programmer
Sep 21, 2009
2
US
<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs=" elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:complexType name="uniqueString">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="uuid" type="uuid" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="uniqueString" type="uniqueString" abstract="true"/>

<xs:simpleType name="uuid">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="uniqueUuid">
<xs:simpleContent>
<xs:extension base="uuid">
<xs:attribute name="uuid" type="uuid" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="uniqueUuid" type="uniqueUuid" abstract="true"/>
<xs:element name="parent" type="uniqueString" abstract="true"/>
<xs:element name="child" type="uniqueString" abstract="true"/>
<xs:element name="hierarchy" abstract="true">
<xs:complexType>
<xs:sequence>
<xs:element ref="parent"/>
<xs:element ref="child" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="hierarchy">
<xs:sequence>
<xs:element ref="hierarchy"/>
</xs:sequence>
</xs:complexType>

<xs:element name="xHierarchy" substitutionGroup="hierarchy"/>
<xs:element name="containingX" substitutionGroup="parent"/>
<xs:element name="containedX" substitutionGroup="child"/>

<xs:element name="X">
<xs:complexType>
<xs:sequence>
<xs:element name="xHierarchy" type="hierarchy"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="yHierarchy" substitutionGroup="hierarchy"/>
<xs:element name="containingY" substitutionGroup="parent"/>
<xs:element name="containedY" substitutionGroup="child"/>

<xs:element name="Y">
<xs:complexType>
<xs:sequence>
<xs:element name="yHierarchy" type="hierarchy"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

given the above schema definition containingX can be used interchangably with containingY and containedX can be used interchangably with containedY. This is undesirable for the system I'm working on - is there a way to all multiple hierarchy elements to be defined within a single .xsd that are derived from the same hierarchy complexType without having interchangable parent elements and interchangable child elements.
 
Instead of one parent and one child as head elements, just devise two parentX and parentY, and childX and childY as head elements. As far as the "hierarchy", it concerns more the types which are here in a normal progression without duplication or collision. Having two head elements should not be considered a weak point of design, or should it?
 
[1]
[tt]<xs:element name="parent[red]X[/red]" type="uniqueString" abstract="true"/>
<xs:element name="child[red]X[/red]" type="uniqueString" abstract="true"/>
<xs:element name="[red]x[/red]hierarchy" abstract="true">
<xs:complexType>
<xs:sequence>
<xs:element ref="parent[red]X[/red]"/>
<xs:element ref="child[red]X[/red]" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="[red]x[/red]hierarchy">
<xs:sequence>
<xs:element ref="[red]x[/red]hierarchy"/>
</xs:sequence>
</xs:complexType>

<xs:element name="xHierarchy" substitutionGroup="[red]x[/red]hierarchy"/>
<xs:element name="containingX" substitutionGroup="parent[red]X[/red]"/>
<xs:element name="containedX" substitutionGroup="child[red]X[/red]"/>

<xs:element name="X">
<xs:complexType>
<xs:sequence>
<xs:element [red]ref[/red]="xHierarchy" />
</xs:sequence>
</xs:complexType>
</xs:element>
[/tt]
[1.1] Same copy for Y.

[2] Now, you have only two elements each in substitutionGroup X and Y, one head element of type abstract. Hence, effectively, only the other element than head element can appear in the instance document. Make sure you want that: it makes sense only if you have intention to open a window to allow more elements into the substitutionGroup in the future when time comes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top