xml schema: rule between atribute value in one element

Discussion in 'XML' started by ocelka, Mar 17, 2005.

  1. ocelka

    ocelka Guest

    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"
    ocelka, Mar 17, 2005
    #1
    1. Advertising

  2. 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


    "ocelka" <> wrote in message
    news:...
    >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"
    Stan Kitsis [MSFT], Mar 18, 2005
    #2
    1. Advertising

  3. ocelka

    Romin Guest

    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.
    Romin, Mar 18, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page