hi all
i'm having xml trouble; i'm not a total beginner, but i'm neither is this my day job -- it's just a small offshoot of something i'm working on for a personal project. i'm sure someone else has already resolved this issue but googling hasn't helped me find a viable solution.
essentially i *think* i'm looking for how to do "if-then" in XSD.
though i may just be going about it the wrong way.
i'm creating an xsd schema which, among other things, has data values that are defined (or not) using Basic SI units; or derived SI units, or context dependent etc.
so it will allow elements that look like this:
(i paste it below first as entities, and then further below as characters)
<data>
<value>34</value>
<unit symbol="C" type="basicSI">Celsius</unit>
</data>
(where if "basicSI" is the type, then symbol MUST come from a prearranged selection; but if "contextDependent" is the type, then any symbol is validatable, as below
<data>
<value>24</value>
<unit symbol="mySymbol" type="contextDependent">myUnit</unit>
</data>
now, *if* someone selects type="basicSI" then i want to restrict the symbol attribute they can use; but *if* they select type="contextDependentUnits" then they should be able to use any symbol they like.
at the moment i have the XSD as below, but this restricts all symbol attributes to the basicSI values.
is there a way to do "if-then"? i can't seem to get it to work with xsd:choice
i'd be grateful for any pointers!
thanks
charles
below is an extract from my xsd:
the extract from the xsd was:
<xsd:element minOccurs="0" maxOccurs="1" name="unit">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="symbol">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Gy" />
<xsd:enumeration value="pH" />
<xsd:enumeration value="Bq" />
<xsd:enumeration value="mol" />
.....
...../
<xsd:enumeration value="K" />
<xsd:enumeration value="s" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="type" use="optional">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="basicSI" />
<xsd:enumeration value="derivedSI" />
<xsd:enumeration value="conversionBasedUnits" />
<xsd:enumeration value="derivedUnits" />
<xsd:enumeration value="contextDependentUnits" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<data>
<value>34</value>
<unit symbol="C" type="basicSI">Celsius</unit>
</data>
<data>
<value>24</value>
<unit symbol="mySymbol" type="contextDependent">myUnit</unit>
</data>
<xsd:element minOccurs="0" maxOccurs="1" name="unit">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="symbol">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Gy" />
<xsd:enumeration value="pH" />
<xsd:enumeration value="Bq" />
<xsd:enumeration value="mol" />
.....
...../
<xsd:enumeration value="K" />
<xsd:enumeration value="s" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="type" use="optional">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="basicSI" />
<xsd:enumeration value="derivedSI" />
<xsd:enumeration value="conversionBasedUnits" />
<xsd:enumeration value="derivedUnits" />
<xsd:enumeration value="contextDependentUnits" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
a
i'm having xml trouble; i'm not a total beginner, but i'm neither is this my day job -- it's just a small offshoot of something i'm working on for a personal project. i'm sure someone else has already resolved this issue but googling hasn't helped me find a viable solution.
essentially i *think* i'm looking for how to do "if-then" in XSD.
though i may just be going about it the wrong way.
i'm creating an xsd schema which, among other things, has data values that are defined (or not) using Basic SI units; or derived SI units, or context dependent etc.
so it will allow elements that look like this:
(i paste it below first as entities, and then further below as characters)
<data>
<value>34</value>
<unit symbol="C" type="basicSI">Celsius</unit>
</data>
(where if "basicSI" is the type, then symbol MUST come from a prearranged selection; but if "contextDependent" is the type, then any symbol is validatable, as below
<data>
<value>24</value>
<unit symbol="mySymbol" type="contextDependent">myUnit</unit>
</data>
now, *if* someone selects type="basicSI" then i want to restrict the symbol attribute they can use; but *if* they select type="contextDependentUnits" then they should be able to use any symbol they like.
at the moment i have the XSD as below, but this restricts all symbol attributes to the basicSI values.
is there a way to do "if-then"? i can't seem to get it to work with xsd:choice
i'd be grateful for any pointers!
thanks
charles
below is an extract from my xsd:
the extract from the xsd was:
<xsd:element minOccurs="0" maxOccurs="1" name="unit">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="symbol">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Gy" />
<xsd:enumeration value="pH" />
<xsd:enumeration value="Bq" />
<xsd:enumeration value="mol" />
.....
...../
<xsd:enumeration value="K" />
<xsd:enumeration value="s" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="type" use="optional">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="basicSI" />
<xsd:enumeration value="derivedSI" />
<xsd:enumeration value="conversionBasedUnits" />
<xsd:enumeration value="derivedUnits" />
<xsd:enumeration value="contextDependentUnits" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<data>
<value>34</value>
<unit symbol="C" type="basicSI">Celsius</unit>
</data>
<data>
<value>24</value>
<unit symbol="mySymbol" type="contextDependent">myUnit</unit>
</data>
<xsd:element minOccurs="0" maxOccurs="1" name="unit">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="symbol">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Gy" />
<xsd:enumeration value="pH" />
<xsd:enumeration value="Bq" />
<xsd:enumeration value="mol" />
.....
...../
<xsd:enumeration value="K" />
<xsd:enumeration value="s" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="type" use="optional">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="basicSI" />
<xsd:enumeration value="derivedSI" />
<xsd:enumeration value="conversionBasedUnits" />
<xsd:enumeration value="derivedUnits" />
<xsd:enumeration value="contextDependentUnits" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
a