Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re-using a simple type definition; with enumeration constraint and without enumeration constraint >Thread Next - Re: Re-using a simple type definition; with enumeration constraint and without enumeration constraint Re: Re-using a simple type definition; with enumeration constraint and without enumeration constraintTo: NULL Date: 2/1/2008 1:37:00 AM On 30 Jan, 22:35, puvit82 <puvis...@gmail.com> wrote:
> My problem is as follows, any advice / suggestion would be greatly
> appreciated:
>
> Lets suppose that I have defined a simpleType "addressType" with 3
> enumeration values (Home, Office, Vacation) that restrict data entry.
> I want to use this simpleType in 2 different unrelated complexType
> definitions, lets call them "personalAddress" and "companyAddress"
>
> How will I be able to use "addressType" inside "personalAddress" such
> that the 3 enumeration values are taken into consideration, i.e. data
> entry is restricted to either one of those three enumeration values
> and also use the same "addressType" inside "companyAddress" such that
> the enumeration values are not considered and the user can enter a
> completely different value for addressType (such as "HomeOffice" and
> the schema validates the XML file)?
>
> I do not want to create another addressType (one with enumerations and
> one without - and different names)
>
> Does anybody think that there is a way to re use the same simple type
> twice; once with the enumeration values and another time without the
> enumeration values?
One thing you might be able to do is define your addressType to be a
list of types, e.g. in an XML instance it might look like:
addressType="Home Office"
The XML schema for that would look something like:
<xs:simpleType name="addressType">
<xs:list>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Home"/>
<xs:enumeration value="Office"/>
<xs:enumeration value="Vacation"/>
</xs:restriction>
</xs:simpleType>
</xs:list>
</xs:simpleType>
or you could make the xs:enumeration 'open' by including an xs:union
of the enumeration and xs:string. However, this does weaken the
amount of validation that can be automatically done.
HTH,
Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/ for XML C++ data binding
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
