Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Wed, 02 Jul 2008 16:55:37 +0100,    group: microsoft.public.xml        back       


XSD schema for optional child elements   
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.
date: Wed, 02 Jul 2008 16:55:37 +0100   author:   Aled Hughes

Re: XSD schema for optional child elements   
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/
date: Wed, 02 Jul 2008 18:17:33 +0200   author:   Martin Honnen

Re: XSD schema for optional child elements   
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.
date: Wed, 02 Jul 2008 17:41:41 +0100   author:   Aled Hughes am

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us