Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: Include multiple complex types into one element ...

From: Dragon Fly <dragon-fly999@-------.--->
To: Andrew Welch <andrew.j.welch@-----.--->
Date: 7/9/2008 4:01:00 AM
Thank you both for the information.  Andrew=2C what is the benefit of defin=
ing a "simple" element globally? For example=2C the nameGroup can be define=
d as follows (i.e. no refs are used for the FirstName and LastName elements=
).

<xs:group name="nameGroup">
  <xs:sequence>
    <xs:element name="FirstName" type="non-empty-string"/>
    <xs:element name="LastName" type="non-empty-string"/>
  </xs:sequence>
</xs:group>

> Date: Wed=2C 9 Jul 2008 10:11:45 +0100
> From: andrew.j.welch@g...
> To: dragon-fly999@h...
> CC: xmlschema-dev@w...
> Subject: Re: Include multiple complex types into one element ...
> 
> 
> > I'm new to XSD and was wondering if I could include multiple complex ty=
pes
> > into one element.  For example=2C I have two complex types NameType and
> > AddressType.
> >
> > =====
> >
> >   <xs:complexType name="NameType">
> >     <xs:sequence>
> >       <xs:element name="FirstName" type="xs:string" />
> >       <xs:element name="LastName" type="xs:string" />
> >     </xs:sequence>
> >   </xs:complexType>
> >
> >   <xs:complexType name="AddressType">
> >     <xs:sequence>
> >       <xs:element name="Country" type="xs:string" />
> >       <xs:element name="Zip" type="xs:string" />
> >     </xs:sequence>
> >   </xs:complexType>
> 
> 
> As you're new here's a schema which should demonstrate a few things to
> get you going.
> 
> First it's in the "Garden of Eden" style which is great name for
> something as simple as defining all of the elements and types globally
> - notice how all of the elements are defined first at the top=2C then
> the simple types and groups=2C then the complex types.  No definition is
> anonymous (hidden within another definition).   This is by far the
> best way of writing your schema.
> 
> Next notice how the names are defined as "non-empty-string" - this is
> a custom simple type because the inbuilt "xs:string" type allows the
> empty string (both " " and "").... which is usually not what you need.
>  Countries are defined using an enumeration=2C and the Zip code is a
> regex.
> 
> Groups are fairly straightforward=2C allowing you to reuse blocks of
> elements=2C and the complexType root is just those groups one after the
> other.  You don't have to use the groups here - you could just
> reference the four elements directly within the "root" type and they
> must occur in that order...
> 
> 
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     elementFormDefault="qualified">
> 
>   <xs:element name="root" type="root"/>
>   <xs:element name="FirstName" type="non-empty-string"/>
>   <xs:element name="LastName" type="non-empty-string"/>
>   <xs:element name="Country" type="country"/>
>   <xs:element name="Zip" type="zip"/>
> 
>   <xs:simpleType name="country">
> 		<xs:restriction base="xs:string">
> 			<xs:enumeration value="Cornwall"/>
> 			<xs:enumeration value="United Kingdom"/>
> 			<xs:enumeration value="Canada"/>
> 		</xs:restriction>
> 	</xs:simpleType>
> =09
>   <xs:simpleType name="zip">
> 	  <xs:restriction base="xs:string">
> 			<xs:pattern value="us zip code regex"/>
> 	  </xs:restriction>=09
>   </xs:simpleType>
> 
>   <xs:group name="nameGroup">
>   	<xs:sequence>
> 		  <xs:element ref="FirstName"/>
> 		  <xs:element ref="LastName"/>=09
> 	  </xs:sequence>
>   </xs:group>
>   =09
>   <xs:group name="addressGroup">
>   	<xs:sequence>
> 		  <xs:element ref="Country"/>
> 		  <xs:element ref="Zip"/>=09
> 	  </xs:sequence>
>   </xs:group>
> 
>   <xs:complexType name="root">
> 	    <xs:sequence>
> 		      <xs:group ref="nameGroup"/>
> 		      <xs:group ref="addressGroup"/>
> 	    </xs:sequence>
>   </xs:complexType>
> 
>   <xs:simpleType name="non-empty-string">
> 	    <xs:restriction base="xs:string">
> 		      <xs:whiteSpace value="collapse"/>
> 		      <xs:minLength value="1"/>
> 	    </xs:restriction>
>   </xs:simpleType>
> </xs:schema>
> 
> 
> hopefully this is helpful...
> 
> -- 
> Andrew Welch
> http://andrewjwelch.com
> Kernow: http://kernowforsaxon.sf.net/
> 

_________________________________________________________________
It=92s a talkathon =96 but it=92s not just talk.
http://www.imtalkathon.com/?source=EML_WLH_Talkathon_JustTalk=


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent