I am feeling my way with XML/Schema and having trouble designing a schema that will allow for some data to be required and in sequence, followed by some that is not. This XML snippet is an example:
Each Patient is required to have LastName and FirstName in that order. This would be followed by episodes of PsychiatricTreatment and MedicalTreatment. Both categories can have 0-unbounded entries in any order.
It seems to me that this should be represented by a group, but I'm not getting it. Here is what I have:
The solution turned out to be xs:choice rather than xs:all. I misunderstood the element restriction of maxOccurs="1", which actually means that while only 1 element at a time can be chosen, the choice can be made as many times as needed. For a detailed
discussion, see the W3Schools Schema forum, where I was disabused of my preconceptions:
echotrain
Member
22 Points
15 Posts
Schema Design for Mixed Required/Optional and Sequential/Unordered
Mar 01, 2012 09:13 PM|LINK
Hello,
I am feeling my way with XML/Schema and having trouble designing a schema that will allow for some data to be required and in sequence, followed by some that is not. This XML snippet is an example:
Each Patient is required to have LastName and FirstName in that order. This would be followed by episodes of PsychiatricTreatment and MedicalTreatment. Both categories can have 0-unbounded entries in any order.
It seems to me that this should be represented by a group, but I'm not getting it. Here is what I have:
<xs:element name="Patient"> <xs:complexType> <xs:sequence> <xs:element ref="LastName" /> <xs:element ref="FirstName" /> <xs:group ref="TreatmentGroup" /> </xs:sequence> </xs:complexType> </xs:element><xs:group name="TreatmentGroup"> <xs:all> <xs:element name="PsychiatricTreatment" /> <xs:element name="MedicalTreatment" /> </xs:all>I would very much appreciate anything that could be pointed out to me.
echotrain
Member
22 Points
15 Posts
Re: Schema Design for Mixed Required/Optional and Sequential/Unordered
Mar 05, 2012 02:38 PM|LINK
The solution turned out to be xs:choice rather than xs:all. I misunderstood the element restriction of maxOccurs="1", which actually means that while only 1 element at a time can be chosen, the choice can be made as many times as needed. For a detailed discussion, see the W3Schools Schema forum, where I was disabused of my preconceptions:
http://w3schools.invisionzone.com/index.php?showtopic=42122