I have searched the mailing list archives (user and dev) and checked Jira but I cannot find anything that exactly matches this potential problem (most if not all of the issues are with the combination of "group" with "choice"). This may mean that I am misunderstanding the XSD spec. but I am sure that someone will let me know if that is the case!
I am trying to create a schema definition for an element that must contain either or both of two sub-elements. I do not want to make both sub-elements optional because I want to ensure that users send at least one of them but I cannot use "choice" because I want users to be able to send both elements if necessary. I thought that element groups might be the answer and so this is the schema I created (test_group.xsd): <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="root"> <xsd:complexType> <xsd:sequence> <xsd:element ref="elements" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="elements"> <xsd:complexType> <xsd:sequence> <xsd:element name="element1" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:group ref="element_group" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:group name="element_group"> <xsd:sequence> <xsd:element name="element2" type="xsd:string" minOccurs="0" maxOccurs="1"/> <xsd:element name="element3" type="xsd:string" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:group> </xsd:schema> Note that both elements within the group are optional but the group is specified as mandatory within the definition of "elements" (minOccurs = 1). This is the test data: <?xml version="1.0"?> <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test_group.xsd"> <elements> <element1>aaaa</element1> </elements> <elements> <element1>aaaa</element1> <element2>bbbb</element2> </elements> <elements> <element1>aaaa</element1> <element3>cccc</element3> </elements> <elements> <element1>aaaa</element1> <element2>bbbb</element2> <element3>cccc</element3> </elements> </root> I expected the first occurrence of "<elements>" to fail (neither <element2> nor <element3> is present) but the file passed validation. Is it Xerces-J (2.8.0), the schema or my understanding that is incorrect and, if it is not the Xerces-J, is there a way to do what I want in a W3C schema? Note: Validation against a DTD showed the same problem. Thanks, Andrew All opinions are completely my own - after all, who else would want to take credit for them? --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
