Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - XSD schema for optional child elements >Thread Next - Re: XSD schema for optional child elements Re: XSD schema for optional child elementsTo: NULL Date: 7/2/2008 6:18:00 PM
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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
