[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Versioning of Enums

  • To: xml-dev@l...
  • Subject: Versioning of Enums
  • From: "Fraser Goffin" <goffinf@h...>
  • Date: Sun, 12 Feb 2006 12:42:35 +0000
  • Bcc:

xsd enums
It appears to be a common practice when, if you have a schema which includes 
a volatile code-list (enumeration), to externalise it into its own 
[chameleon] schema and then include that schema into the main [transaction] 
schema. I just wanted to see whether others have experience of using this 
approach and if any issues arise from it ?

In our case the enumerated values of of type xs:string (not sure if this 
matters but it might)

We also get our schema from a standards body who define the standard market 
values. Naturally :-) my business colleagues are not always satisfied with 
that and want to both extend and restrict the values used. So in this case I 
am thinking of :-

a. creating another schema to contain OUR custom enum values
b. creating another schema that imports my custom codes and the market 
standard and :-
    - contains a type which is a restriction of the market standard enum
    - contains a type which is a union of the restricted market standard and 
custom enum.

Does this seems reasonable ? here's a rough example using the oft described 
'currency code' example :-

Market Standard Schema (BaseCodes.xsd)
===============

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="qualified" version="1.0">
	<xs:simpleType name="iso3currency">
		<xs:annotation>
			<xs:documentation>ISO-4217 3-letter currency codes. Only a subset are 
defined here.</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
			<xs:length value="3"/>
			<xs:enumeration value="AUD"/>
			<xs:enumeration value="BRL"/>
			<xs:enumeration value="CAD"/>
			<xs:enumeration value="CNY"/>
			<xs:enumeration value="EUR"/>
			<xs:enumeration value="GBP"/>
			<xs:enumeration value="INR"/>
			<xs:enumeration value="JPY"/>
			<xs:enumeration value="RUR"/>
			<xs:enumeration value="USD"/>
		</xs:restriction>
	</xs:simpleType>
</xs:schema>

My Custom Schema (MYCurrencyCodes.xsd)
============

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns="http://www.someorg.com/ws/2006/02/codelists" 
targetNamespace="http://www.someorg.com/ws/2006/02/codelists" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:simpleType name="iso3currency">
		<xs:restriction base="xs:string">
			<xs:length value="3"/>
			<xs:enumeration value="abc"/>
			<xs:enumeration value="def"/>
			<xs:enumeration value="ghi"/>
			<xs:enumeration value="jkl"/>
			<xs:enumeration value="mno"/>
			<xs:enumeration value="pqr"/>
			<xs:enumeration value="stu"/>
			<xs:enumeration value="vwx"/>
			<xs:enumeration value="yza"/>
		</xs:restriction>
	</xs:simpleType>
</xs:schema>

The schema to INCLUDE in the main transaction (CombinedCurrencyCodes.xsd)
=============================

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:my="http://www.someorg.com/ws/2006/02/codelists" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:include schemaLocation="BaseCodes.xsd"/>
	<xs:import namespace="http://www.someorg.com/ws/2006/02/codelists" 
schemaLocation="MYCurrencyCodes.xsd"/>
	<xs:simpleType name="iso3currencyRestricted">
		<xs:restriction base="iso3currency">
			<xs:enumeration value="CNY"/>
			<xs:enumeration value="EUR"/>
			<xs:enumeration value="GBP"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="MYiso3currency">
		<xs:union memberTypes="iso3currencyRestricted my:iso3currency"/>
	</xs:simpleType>
</xs:schema>

The main schema
===========

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns="urn:www.polaris-uk.co.uk/codelist/example" 
targetNamespace="urn:www.polaris-uk.co.uk/codelist/example" 
elementFormDefault="qualified">
	<xs:include schemaLocation="CombinedCurrencyCodes.xsd"/>
	<xs:element name="accountSummary">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="timestamp"/>
				<xs:element ref="currency"/>
				<xs:element ref="balance"/>
				<xs:element ref="interest"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="timestamp" type="xs:dateTime"/>
	<xs:element name="currency" type="MYiso3currency"/>
	<xs:element name="balance" type="xs:decimal"/>
	<xs:element name="interest">
		<xs:complexType>
			<xs:simpleContent>
				<xs:extension base="xs:decimal">
					<xs:attribute name="rounding" type="roundingDirection" use="required"/>
				</xs:extension>
			</xs:simpleContent>
		</xs:complexType>
	</xs:element>
	<xs:simpleType name="roundingDirection">
		<xs:annotation>
			<xs:documentation>Whether the interest is rounded up, down, or to the 
nearest round value.</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
			<xs:enumeration value="up"/>
			<xs:enumeration value="down"/>
			<xs:enumeration value="nearest"/>
		</xs:restriction>
	</xs:simpleType>
</xs:schema>



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.