Re: XML: How to require either or both of two child elements, but prevent both missing?
Hello Donald:
I'm sorry, I have to say I really don´t know because I haven´t tried it out. I just thought it wouldn't allow for 2 B's if you had to choose first between an A[B] element and a B element. But anyway I couldn't agree more with you: it surely gets too messy, specially if it's one of the first elements in the hierarchy, as this seems the case.
See you next week,
William.
-----Original Message----- From: Hobern, Donald [mailto:DHobern@GBIF.ORG] Sent: Domingo 23 de Febrero de 2003 02:26 AM To: TDWG-SDD@USOBI.ORG Subject: Re: XML: How to require either or both of two child elements, but prevent both missing?
Wouldn't this example too would allow for 2 B's? It may be messy (especially if you progress beyond two elements), but couldn't you just use a choice allowing for only one of an A-B group, an A or a B?
Donald Hobern
-----Original Message----- From: William Ulate To: TDWG-SDD@USOBI.ORG Sent: 23/02/03 00:08 Subject: Re: XML: How to require either or both of two child elements, but prevent both missing? Importance: High
Hello:
Wouldn´t this allow for the case when there are two A's or two B's?
I haven't tried it yet but, I just glanced at the spec and found an example that would yield something like this if applied:
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Parent"> xs:complexType xs:choice <xs:group ref="elementABopt"/> <xs:element ref="elementB" minOccurs="1"/> </xs:choice> </xs:complexType> </xs:element>
<xs:element name="elementABopt"> xs:complexType xs:sequence <xs:element ref="elementA" minOccurs="1"/> <xs:element ref="elementB" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element>
<xs:element name="elementA"> </xs:element>
<xs:element name="elementB"> </xs:element>
</xs:schema>
Do you see any problem here (besides complexity?)
Hope this helps...
Greetings,
William.
-----Original Message----- From: Jim Croft [mailto:jrc@ANBG.GOV.AU] Sent: Sábado 22 de Febrero de 2003 04:43 PM To: TDWG-SDD@USOBI.ORG Subject: Re: XML: How to require either or both of two child elements, but prevent both missing?
How in XML-schema do you make sure that of two possible child elements, either or both, but not neither are present?
How about changing the model to 'choice' and requiring one but allowing two (or multiple) occurrences of optional elements?
something like this maybe?
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Parent"> xs:complexType <xs:choice minOccurs="1" maxOccurs="2"> <xs:element name="A" minOccurs="0" maxOccurs="1"/> <xs:element name="B" minOccurs="0" maxOccurs="1"/> </xs:choice> </xs:complexType> </xs:element> </xs:schema>
~ Jim Croft ~ jrc@anbg.gov.au ~ 02-62465500 ~ www.anbg.gov.au/jrc/ ~
participants (1)
-
unknown@example.com