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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[XSD] xml elements restricting the occurance of other elements

Status
Not open for further replies.

lode004

Programmer
Jun 3, 2008
4
Hi,

An extract of the xsd file i have:

<xs:element name="Side">
<xs:complexType>
<xs:sequence>
<xs:element name="CIRC" type="xs:double" default="0.00">
<xs:annotation>
<xs:documentation>Circumference</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="FBOCIN" type="xs:double" default="0.0">
<xs:annotation>
<xs:documentation>Finish block to prism reference point offsets (mm). Can be used for single vision and for multifocals. +IN means PRP is towards nasal relative to the finish block. -IN means PRP is towards temporal relative to the finish block. Also known as X decentration.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="FBOCUP" type="xs:double" default="0.0">
<xs:annotation>
<xs:documentation>Finish block to prism reference point offsets (mm). Can be used for single vision and for multifocals. +UP means PRP is above the finish block. -UP means PRP is below the finish block. Also known as Y decentration.</xs:documentation>
</xs:annotation>
</xs:element>
...
A whole lot more elements here
...

</xs:sequence>
<xs:attribute name="type" type="side_type" use="required">
<xs:annotation>
<xs:documentation>L = Left side; R = Right side</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>

For the question i have there are 2 important elements:
FBOCIN & FBOCUP
Is there a way to define in the xsd that if the FBOCIN element occures that the FBOCUP shouldn't and vise versa?

Anyone has a suggestion?
Thanks in advance
 
[1] You can at their place, wrap them in a choice element.
[tt]
<xs:choice>
<xs:element name="FBOCIN" type="xs:double" default="0.0">
<!-- etc etc -->
</xs:element>
<xs:element name="FBOCUP" type="xs:double" default="0.0">
<!-- etc etc -->
</xs:element>
</xs:choice>
[/tt]
[2] If that looks a bit distracting, you can define both element as a top-element elements and use ref in the choice element.
[tt]
<xs:choice>
<xs:element ref="FBOCIN" />
<xs:element ref="FBOCUP" />
</xs:choice>
[/tt]
[3] You can as well further define a (choice) group and place xs:group element at that place.
[tt]
<xs:group ref="the-choice-group-name" />
[/tt]
[4] ... and more variations of the same idea.
 
aha, very intresting, thanks for the answer,

so the extract i used to provide looks like this now,...


<xs:element name="Side">
<xs:annotation>
<xs:documentation>max. 2 occurances</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="CIRC" type="xs:double" default="0.00">
<xs:annotation>
<xs:documentation>Circumference</xs:documentation>
</xs:annotation>
</xs:element>
<xs:choice>
<xs:sequence>
<xs:element name="FBOCIN" type="xs:double" default="0.0">
<xs:annotation>
<xs:documentation>Finish block to prism reference point offsets (mm). Can be used for single vision and for multifocals. +IN means PRP is towards nasal relative to the finish block. -IN means PRP is towards temporal relative to the finish block. Also known as X decentration.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:sequence>
<xs:element name="FBOCUP" type="xs:double" default="0.0">
<xs:annotation>
<xs:documentation>Finish block to prism reference point offsets (mm). Can be used for single vision and for multifocals. +UP means PRP is above the finish block. -UP means PRP is below the finish block. Also known as Y decentration.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:choice>
</xs:sequence>
<xs:attribute name="type" type="side_type" use="required">
<xs:annotation>
<xs:documentation>L = Left side; R = Right side</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>



u ve been a great help, thanks alot
 
Without the xs:sequence element in the xs:choice construction, I think? no?
 
yea, if it would be only 1 element in the choice, but actualy its a group of elements, theres either FBOCIN, FBOCUP, IPD and OCHT, OR the other group FBSGIN, FBSGUP, NPD, SEGHT

so guess a choice of 2 sequences is a good option than, right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top