xml schema: rule between atribute value in one element

O

ocelka

I need know how define xml schema for this xml fragment:

<set name="person-id" value="secure-card"/>
<set name="person-id" value="thumb-print"/>

<set name="length-unit" value="inch"/>
<set name="length-unit" value="cm"/>

so if name="person-id", then value can contain only one of value
"secure-card","thumb-print".
if name="length-unit", then value can contain only one of value
"inch","cm"
 
S

Stan Kitsis [MSFT]

You can't define that in XML Schema. What you can do is define the
following:

<personID value="secure-card"/>
<personID value="thumb-print"/>
<lengthUnit value="inch"/>
<lengthUnit value="cm"/>

using the following schema:

<xs:element name="personID">

<xs:complexType>

<xs:attribute name="value" type="personAtt"/>

</xs:complexType>

</xs:element>

<xs:element name="lengthUnit">

<xs:complexType>

<xs:attribute name="value" type="lengthAtt"/>

</xs:complexType>

</xs:element>

<xs:simpleType name="personAtt">

<xs:restriction base="xs:string">

<xs:enumeration value="secure-card"/>

<xs:enumeration value="thumb-print"/>

</xs:restriction>

</xs:simpleType>

<xs:simpleType name="lengthAtt">

<xs:restriction base="xs:string">

<xs:enumeration value="inch"/>

<xs:enumeration value="cm"/>

</xs:restriction>

</xs:simpleType>


--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation


This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
R

Romin

To ht best of my knowledge -- I dont think XML Schema supports your
conditional kind of validation.

I suggest taking a look at an alternative way i.e. XML Schematron
(Conditional Constraints are supported). Or you could think in terms of
XSLT itself i.e. write an XSLT that will be used as a way to validate.
However I am not sure if the this would be worth in the effort in the
overall context of what you are trying to validate here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top