W3C schema 'if..then' for attributes

S

shaun

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
 
S

Soren Kuula

shaun said:
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
 
S

shaun

Peter Flynn said:
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

???
 
P

Peter Flynn

shaun said:
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
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top