Hi, I'm trying to figure out how to validate an element in XML with XML Schema that can either have no content or a couple of child elements. Example: <foo id="123"> <bar str="abc"/> </foo> <foo id="321"/> I can get XSD to validate one or the other but not accept both. Any ideas? (I have the minOccurs="0" on the <bar> element definition.) Cheers, aled.
Aled Hughes wrote: > Hi, > I'm trying to figure out how to validate an element in XML with XML > Schema that can either have no content or a couple of child elements. > > Example: > > <foo id="123"> > <bar str="abc"/> > </foo> > > <foo id="321"/> > > I can get XSD to validate one or the other but not accept both. Any > ideas? (I have the minOccurs="0" on the <bar> element definition.) This is an example schema: <xs:element name="foo" maxOccurs="unbounded"> <xs:complexType> <xs:sequence minOccurs="0" maxOccurs="unbounded"> <xs:element name="bar"> <xs:complexType> <xs:attribute name="str" type="xs:string"/> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="id" type="xs:int"/> </xs:complexType> </xs:element> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
Martin Honnen wrote: > Aled Hughes wrote: >> Hi, >> I'm trying to figure out how to validate an element in XML with XML >> Schema that can either have no content or a couple of child elements. >> >> Example: >> >> <foo id="123"> >> <bar str="abc"/> >> </foo> >> >> <foo id="321"/> >> >> I can get XSD to validate one or the other but not accept both. Any >> ideas? (I have the minOccurs="0" on the <bar> element definition.) > > This is an example schema: > > <xs:element name="foo" maxOccurs="unbounded"> > <xs:complexType> > <xs:sequence minOccurs="0" maxOccurs="unbounded"> > <xs:element name="bar"> > <xs:complexType> > <xs:attribute name="str" type="xs:string"/> > </xs:complexType> > </xs:element> > </xs:sequence> > <xs:attribute name="id" type="xs:int"/> > </xs:complexType> > </xs:element> > > > > Thanks Martin. Got it working now.