B
brucepickford001
Hi, I have a not simple problem.
I want the following XML to be schema valid
<PopulationDemographic>
<PersonName>Joe Blogs</PersonName>
<Age>2</Age>
<Category>baby</Category>
</PopulationDemographic>
And I want the following XML to be schema invalid
<PopulationDemographic>
<PersonName>Joe Blogs</PersonName>
<Age>2</Age>
<Category>teenager</Category>
</PopulationDemographic>
I can see how to create the restriction of "baby", "todler",
"teenager" and "pensioner" for my element "Category". I can see how to
restrict the ages to one of "1", "2", "3" ... "110" using similar
code. But I can't work out how to say in the schema
if "Category" = "baby" then valid ages must be "1", "2"
if "Category" = "todler" then valid ages must be "2", "3", "4" and "5"
if "Category" = "teenager" then valid ages must be "13", "14", "15",
"16", "17", "18" and "19"
if "Category" = "pensioner" then valid ages must be "65", "66" ....
"110"
Here is my schema now
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="PopulationDemographic">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonName" type="xs:string"/>
<xs:element name="Age" type="ages"/>
<xs:element name="Category" type="category"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="category">
<xs:restriction base="xs:string">
<xs:enumeration value="baby"/>
<xs:enumeration value="todler"/>
<xs:enumeration value="teenager"/>
<xs:enumeration value="pensioner"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ages">
<xs:restriction base="xs:string">
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
<xs:enumeration value="3"/>
<xs:enumeration value="4"/>
<!-- all the others up to 110 -->
</xs:restriction>
</xs:simpleType>
</xs:schema>
How can I do this? I have a feeling there is going to be an xpath and
keyref here somewhere but don't have the skills yet to know this for
certain or write the code (I am using xmlspy and the book xml in a
nutshell).
If anyone has an online reference, a pseudo code snippet, or help me
out with extending above for say todlers (I will do the rest) I would
really appreciate it.
This is my first post to newsgroup so sorry to have to ask a nasty
question like this without contributing anything first.
Thank you
Bruce
I want the following XML to be schema valid
<PopulationDemographic>
<PersonName>Joe Blogs</PersonName>
<Age>2</Age>
<Category>baby</Category>
</PopulationDemographic>
And I want the following XML to be schema invalid
<PopulationDemographic>
<PersonName>Joe Blogs</PersonName>
<Age>2</Age>
<Category>teenager</Category>
</PopulationDemographic>
I can see how to create the restriction of "baby", "todler",
"teenager" and "pensioner" for my element "Category". I can see how to
restrict the ages to one of "1", "2", "3" ... "110" using similar
code. But I can't work out how to say in the schema
if "Category" = "baby" then valid ages must be "1", "2"
if "Category" = "todler" then valid ages must be "2", "3", "4" and "5"
if "Category" = "teenager" then valid ages must be "13", "14", "15",
"16", "17", "18" and "19"
if "Category" = "pensioner" then valid ages must be "65", "66" ....
"110"
Here is my schema now
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="PopulationDemographic">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonName" type="xs:string"/>
<xs:element name="Age" type="ages"/>
<xs:element name="Category" type="category"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="category">
<xs:restriction base="xs:string">
<xs:enumeration value="baby"/>
<xs:enumeration value="todler"/>
<xs:enumeration value="teenager"/>
<xs:enumeration value="pensioner"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ages">
<xs:restriction base="xs:string">
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
<xs:enumeration value="3"/>
<xs:enumeration value="4"/>
<!-- all the others up to 110 -->
</xs:restriction>
</xs:simpleType>
</xs:schema>
How can I do this? I have a feeling there is going to be an xpath and
keyref here somewhere but don't have the skills yet to know this for
certain or write the code (I am using xmlspy and the book xml in a
nutshell).
If anyone has an online reference, a pseudo code snippet, or help me
out with extending above for say todlers (I will do the rest) I would
really appreciate it.
This is my first post to newsgroup so sorry to have to ask a nasty
question like this without contributing anything first.
Thank you
Bruce