Altova Mailing List Archives>Archive Index >xmlschema-dev Archive Home >Recent entries >Thread Prev - Re: Include multiple complex types into one element ... >Thread Next - Re: Include multiple complex types into one element ... RE: Include multiple complex types into one element ...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=
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
