W3C schema 'if..then' for attributes

Discussion in 'XML' started by shaun, Sep 20, 2005.

  1. shaun

    shaun Guest

    I should like to allow/disallow values for an attribute based on the
    value of another attribute e.g if I have a document


    <character name="snow white" sex="female" hatcolour=""/>
    <character name="doc" sex="male" hatcolour="brown"/>


    then this is valid. however

    <character name="snow white" sex="female" hatcolour="green"/>

    should be invalid. (in my story, female characters don't wear hats).

    so I should like a schema which will allow hat colours green|brown|red
    etc if the sex = 'male' but only allow the empty string for the hat
    colour if the sex = 'female'.

    is this possible in W3C schema?

    cheers

    shaun
     
    shaun, Sep 20, 2005
    #1
    1. Advertising

  2. shaun

    Soren Kuula Guest

    shaun wrote:
    > I should like to allow/disallow values for an attribute based on the
    > value of another attribute e.g if I have a document


    > so I should like a schema which will allow hat colours green|brown|red
    > etc if the sex = 'male' but only allow the empty string for the hat
    > colour if the sex = 'female'.
    >
    > is this possible in W3C schema?


    No.

    Soren
     
    Soren Kuula, Sep 21, 2005
    #2
    1. Advertising

  3. shaun

    Peter Flynn Guest

    Soren Kuula wrote:

    > shaun wrote:
    >> I should like to allow/disallow values for an attribute based on the
    >> value of another attribute e.g if I have a document

    >
    >> so I should like a schema which will allow hat colours green|brown|red
    >> etc if the sex = 'male' but only allow the empty string for the hat
    >> colour if the sex = 'female'.
    >>
    >> is this possible in W3C schema?

    >
    > No.
    >
    > Soren


    So much for the "Expressiveness of XSDs".

    ///Peter
     
    Peter Flynn, Sep 21, 2005
    #3
  4. shaun

    shaun Guest

    In article <>,
    Peter Flynn <> wrote:

    >Soren Kuula wrote:
    >
    >> shaun wrote:
    >>> I should like to allow/disallow values for an attribute based on the
    >>> value of another attribute e.g if I have a document

    >>
    >>> so I should like a schema which will allow hat colours green|brown|red
    >>> etc if the sex = 'male' but only allow the empty string for the hat
    >>> colour if the sex = 'female'.
    >>>
    >>> is this possible in W3C schema?

    >>
    >> No.
    >>
    >> Soren

    >
    >So much for the "Expressiveness of XSDs".
    >
    >///Peter


    so I cannot declare that the same element could have one of two types,
    (dodgy pseudo code follows):

    choice

    element =" character" type= "female character constraints"
    element="character" type="male character constraints"

    /choice

    ???
     
    shaun, Sep 22, 2005
    #4
  5. shaun

    Peter Flynn Guest

    shaun wrote:

    > In article <>,
    > Peter Flynn <> wrote:
    >
    >>Soren Kuula wrote:
    >>
    >>> shaun wrote:
    >>>> I should like to allow/disallow values for an attribute based on the
    >>>> value of another attribute e.g if I have a document
    >>>
    >>>> so I should like a schema which will allow hat colours green|brown|red
    >>>> etc if the sex = 'male' but only allow the empty string for the hat
    >>>> colour if the sex = 'female'.
    >>>>
    >>>> is this possible in W3C schema?
    >>>
    >>> No.
    >>>
    >>> Soren

    >>
    >>So much for the "Expressiveness of XSDs".
    >>
    >>///Peter

    >
    > so I cannot declare that the same element could have one of two types,
    > (dodgy pseudo code follows):
    >
    > choice
    >
    > element =" character" type= "female character constraints"
    > element="character" type="male character constraints"
    >
    > /choice


    Correct, you can't. But you can use markup to do what you want, and
    you don't need anything so complex as a Schema:

    <?xml version="1.0"?>
    <!DOCTYPE characters [
    <!ELEMENT characters (female|male)+>
    <!ELEMENT female EMPTY>
    <!ATTLIST female name CDATA #REQUIRED hat CDATA #FIXED "">
    <!ELEMENT male EMPTY>
    <!ATTLIST male name CDATA #REQUIRED hat (green|brown|red) #IMPLIED>
    ]>
    <characters>
    <female name="Snow White"/>
    <male name="Doc" hat="brown"/>
    </characters>

    A validating parser will return a null value for the hat attribute for
    all females.

    ///Peter
     
    Peter Flynn, Sep 22, 2005
    #5
    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.
Similar Threads
  1. Frank
    Replies:
    9
    Views:
    1,635
    David Dorward
    May 3, 2004
  2. Steve Jorgensen
    Replies:
    0
    Views:
    580
    Steve Jorgensen
    Aug 9, 2005
  3. Replies:
    1
    Views:
    386
  4. Replies:
    3
    Views:
    3,175
  5. Replies:
    0
    Views:
    338
Loading...

Share This Page