I currently have the following code that will validate a recursive structure. Each level can have any of the element names listed in the substitutionGroup.
<xsd:complexType name="Level1">
<xsd:sequence>
<xsd:element ref="Level2" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="nodeID" type="xsd:integer" use="required" />
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:element name="Level2" type="Level1" />
<xsd:element name="Level3" substitutionGroup="Level2" />
<xsd:element name="Level4" substitutionGroup="Level3" />
<xsd:element name="Level5" substitutionGroup="Level4" />
The following code validates using this schema
<Level1 nodeID="3648" name="1" >
<Level3 nodeID="3649" name="1.1" >
<Level2 nodeID="3650" name="1.1.1" >
</Level2 >
</Level3 >
<Level4 nodeID="3651" name="1.2" >
</Level4 >
</Level1 >
I really want to be able to enforce that Level2 is always in Level1, etc, like the following:
<Level1 nodeID="3648" name="1" >
<Level2 nodeID="3649" name="1.1" >
<Level3 nodeID="3650" name="1.1.1" >
</Level3 >
</Level2 >
<Level2 nodeID="3651" name="1.2" >
</Level2 >
</Level1 >
Is this possible using a substitutionGroup? Or is this something simpler I am missing?
The goal is to validate against the same underlying complexType AND if possible have a list of valid element names in the XSD file.
The main constraint is that the user base wants different levels and level names. I'm trying to keep the structure as simple as possible for adding/removing levels and changing their names from use case to use case.
You could think of this as an indented document structure where each level can have a different name like Chapter, Section, Paragraph. Each person wants to name their sections differently and can more or less levels.
Thanks