- From: Paul Downey via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 14 Jul 2005 14:32:33 +0000
- To: public-ws-desc-eds@w3.org
Update of /sources/public/2002/ws/desc/schema-patterns In directory hutz:/tmp/cvs-serv25621 Modified Files: xml-schema-patterns.html xml-schema-patterns.xml Log Message: first real draft, maps missing Index: xml-schema-patterns.xml =================================================================== RCS file: /sources/public/2002/ws/desc/schema-patterns/xml-schema-patterns.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** xml-schema-patterns.xml 1 Jul 2005 15:32:17 -0000 1.2 --- xml-schema-patterns.xml 14 Jul 2005 14:32:30 -0000 1.3 *************** *** 43,50 **** </authlist> <status id="Status"> <p> ! <emph>The intention is that this document will be published as a Web Services Description ! Working Group Note, although the Working Group has show interest in this work taking ! place, the Working Group has yet to review or approve this document.</emph> </p> </status> --- 43,61 ---- </authlist> <status id="Status"> + <p> This origin if this document stems from discussions surrounding a set of example XML + Schema patterns submitted as examples for the <loc + href="http://www.w3.org/TR/wsdl20-primer/">WSDL 2.0 Primer</loc> [<loc + href="http://lists.w3.org/Archives/Public/www-ws-desc/2004May/0007.html" + >http://lists.w3.org/Archives/Public/www-ws-desc/2004May/0007.html</loc>]. </p> + <p> However, as a result of discussions during the <loc + href="http://www.w3.org/2005/03/xml-schema-user-program.html">W3C Workshop on XML Schema + 1.0 User Experiences</loc>, the W3C may form a dedicated Working Group to <emph>develop a + set of patterns for common data structures of XML Schema for the purpose of simplifying + the mapping of XML Schemas into programming language structures</emph> [<loc + href="http://lists.w3.org/Archives/Public/www-ws/2005Jul/0000.html" + >http://lists.w3.org/Archives/Public/www-ws/2005Jul/0000.html</loc>]. This note may + provide useful input to such a Working Group. </p> <p> ! <emph>The WSD Working Group has yet to review or approve this document.</emph> </p> </status> *************** *** 53,60 **** data structures. The data structures described are intended to be independent of any particular programming language or database or modelling environment.</p> - <p> Authors of tools which map or bind data structures to XML may find these simple patterns - useful in facilitating the mapping of commonplace constructs to and from XML. </p> - <p> Authors of XML Schema 1.0 documents may also find these patterns useful in providing a - good user experience for consumers using data mapping and binding tools. </p> </abstract> <langusage> --- 64,67 ---- *************** *** 68,76 **** <div1 id="introduction"> <head>Introduction</head> ! <p> ! ! <ednote><edtext>Explanation of how schema may be used as a description language, as well as for ! validation. Reference to WSDL which uses XML Schema for such a purpose</edtext></ednote> ! </p> <div2 id="notational"> <head>Notational Conventions</head> --- 75,92 ---- <div1 id="introduction"> <head>Introduction</head> ! <p> This note provides a set of example XML Schema structures <bibref ref="XMLSchemaP1"/> and ! types <bibref ref="XMLSchemaP2"/> which may be used to exchange commonly used data ! structures in the form of an XML document.</p> ! <p>Authors of tools which map or bind data structures to XML may find these patterns useful to ! represent simple and common place constructs. Recognising these patterns and presenting them ! in terms most appropriate to the specific language, database or environment may preserve ! such data structures across boundaries, as well as providing an improved <emph>user ! experience</emph> when using data mapping and binding tools. </p> ! <p> Authors of XML Schema 1.0 documents may find these patterns useful in providing a better ! <emph>user experience</emph> for consumers of their schemas using data mapping and binding ! tools. </p> ! <p>It is not intended that these constructs should constrain the use of the XML Schema ! Recommendation. A processor using these constructs to map data structures should continue to ! support the whole of the XML Schema Recommendation.</p> <div2 id="notational"> <head>Notational Conventions</head> *************** *** 113,126 **** </div1> <div1 id="Data-Structures"> ! <head>Common Data Structures</head> ! <p/> ! <div2 id="Enumerated"> ! <head>Enumerated Types</head> ! <p></p> ! ! <example id="eg-closed-enum"> ! <head>Closed Enumerated Type</head> ! <eg xml:space="preserve"><![CDATA[ <xs:simpleType name='Beatle' > <xs:restriction base='xs:string' > --- 129,148 ---- </div1> <div1 id="Data-Structures"> ! <head>Patterns for Common Data Structures</head> ! <div2 id="Naming"> ! <head>Naming Types</head> ! <p>Giving each data structure an individual type, following the so-called "venetian blind" ! schema authoring style, simplifies mapping to and from a data model.</p> ! <p>The name of a schema type, attribute or element may be any valid XML non-colonized name ! including names which may be reserved or not directly representable in some programming ! languages, such as "object", "static", "final", "class", "Customer-Profile", etc.</p> ! </div2> <div2 id="Enumerated"> ! <head>Enumerated Type</head> ! <p>The XML Schema enumerated type provides a useful mechanism for expressing a controlled ! vocabulary for an element or attribute value. </p> ! <example id="eg-enum"> ! <head>Enumerated Type</head> ! <eg xml:space="preserve"><![CDATA[ <xs:simpleType name='Beatle' > <xs:restriction base='xs:string' > *************** *** 133,288 **** </xs:restriction> </xs:simpleType> ! ]]></eg> ! </example> ! <p> ! </p> ! ! <example id="eg-open-enum"> ! <head>Open Enumerated Type</head> ! <eg xml:space="preserve"><![CDATA[ ! <xs:simpleType name='Fruit' > <xs:restriction base='xs:string' > ! <xs:enumeration value='Apple' /> ! <xs:enumeration value='Pear' /> ! <xs:enumeration value='Banana' /> </xs:restriction> </xs:simpleType> ! <xs:simpleType name='Pudding' > ! <xs:union memberTypes='tns:Fruit xs:string' /> </xs:simpleType> - ]]></eg> - </example> </div2> - <div2 id="Collection"> ! <head>Collections</head> ! <p></p> ! ! <ednote><edtext> ! A collection of data items (an object, class, structure, record etc) ! is best represented as a complexType with the individual items as ! elements and/or attributes. Sadly it needs saying that the compositors ! "sequence", "all" *and* "choice" should be supported. ! </edtext></ednote> ! ! ! <example id="eg-simple-collection"> ! <head>Simple Collection</head> ! <eg xml:space="preserve"><![CDATA[ <xs:complexType name="ProductType"> <xs:sequence> <xs:element name="name" type="xs:string"/> ! <xs:element name="colour" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:string" /> </xs:complexType> ! ]]></eg> ! </example> ! <p></p> ! ! ! <ednote><edtext> ! Explicit (active) extensibility of a collection may be expressed ! using 'any' and 'anyAttribute' as in the following example adapted ! from the draft TAG finding on extensibility and versioning[2]: ! </edtext></ednote> ! ! ! <example id="eg-extended-collection"> ! <head>Extending a Collection</head> ! <eg xml:space="preserve"><![CDATA[ <xs:complexType name="ProductType"> <xs:sequence> ! <xs:element name="name" type="xs:string" ! minOccurs="1" maxOccurs="1"/> ! <xs:element name="colour" type="xs:string"/> ! <xs:any processContents="lax" ! minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="id" type="xs:string" /> ! <xs:anyAttribute/> </xs:complexType> ! ]]></eg> ! </example> ! ! <ednote><edtext> ! The 'any' wildcard is only deterministic when applied to the end of ! a 'sequence' - determinism being particularly important when generating ! messages from a schema definition. Again it needs saying that tools ! should support the 'namespace' attribute including the '##any', ! '##other' and '# ! </edtext></ednote> ! ! <ednote> ! <edtext>Add Dare Obasanjo's pattern for subverting greedy 'any'.</edtext> ! </ednote> </div2> <div2 id="Vector"> ! <head>Vectors</head> ! <p> ! ! A vector is an ordered sequence of items of the same data type. This is ! a very common construct in programming languages appearing as an array or ! list. Multi-dimensional arrays may be built by composing vectors within ! vectors. Formalising more complex constructs such as sparse or jagged ! matrices are beyond the scope of these examples. ! </p> ! ! <example id="eg-wrapped-vector"> ! <head>Wrapped Vector</head> ! <eg xml:space="preserve"><![CDATA[ ! <xsd:complexType name="ItemList"> <xsd:sequence> <xsd:element name="item" type="xsd:string" minOccurs=0 maxOccurs="unbounded"/> ! </xsd:sequence> </xsd:complexType> ! ]]></eg> ! </example> ! ! <example id="eg-bare-vectors"> ! <head>Bare Vector</head> ! <eg xml:space="preserve"><![CDATA[ ! <xs:complexType name="Address"> ! <xs:sequence> ! <xs:element name="lines" type="xs:string" maxOccurs="unbounded"/> ! <xs:element name="telnos" type="xs:string" maxOccurs="unbounded"/> ! <xs:sequence> ! </xs:complexType> ! ]]></eg> ! </example> ! </div2> ! <div2 id="Maps"> ! <head>Maps</head> ! <p></p> ! <ednote><edtext> ! xs:ID is similar to the DTD ID type with the following properties: ! ! - the type has the same lexical space as xs:NCName ! - the ID may be an attribute or an element ! - the ID value must be unique with the document ! - there may be one or more ID's associated with an element ! ! </edtext></ednote> ! <ednote><edtext> ! The PSVI set contains a ID/IDREF table[7] which is an index pointing ! to nodes with an included xs:ID element/attribute. ! </edtext></ednote> ! ! <ednote><edtext> ! The new xml:id[8] attribute from the XML Base WG offers an neat way of ! expressing an ID value for an element targeted at recipients who may not ! have access to a schema. A so called 'disengaged' agent may easily more ! recognise a map from a document containing xml:id attributes and present ! the repeated element as an associative array, e.g: ! </edtext></ednote> ! ! <example id="eg-map-xml-id"> ! <head>Map Keyed Using xml:id</head> ! <eg xml:space="preserve"><![CDATA[ <xs:schema targetNamespace="http://www.w3.org/1998/XML/Namespace"> <xs:attribute name="id" type="xs:ID"/> --- 155,414 ---- </xs:restriction> </xs:simpleType> ! ]]></eg> ! </example> ! </div2> ! <div2 id="Enumerated-Open"> ! <head>Open Enumerated Type</head> ! <p>Reusing the enumeration in a union with the base type or in combination with other ! enumerations may be used to express a vocabulary open to additional values. </p> ! <example id="eg-open-enum"> ! <head>Open Enumerated Type</head> ! <eg xml:space="preserve"><![CDATA[ ! <xs:simpleType name='AppleVariety' > <xs:restriction base='xs:string' > ! <xs:enumeration value='Braeburn' /> ! <xs:enumeration value='Cox' /> ! <xs:enumeration value='Egremont Russet' /> ! <xs:enumeration value='Granny Smith' /> </xs:restriction> </xs:simpleType> ! <xs:simpleType name='PlumVariety' > ! <xs:restriction base='xs:string' > ! <xs:enumeration value='Damson' /> ! <xs:enumeration value='Greengage' /> ! <xs:enumeration value='Victoria' /> ! </xs:restriction> </xs:simpleType> + <xs:simpleType name='FruitVariety' > + <xs:union memberTypes='tns:AppleVariety tns:PlumVariety xs:string' /> + </xs:simpleType> + ]]></eg> + </example> </div2> <div2 id="Collection"> ! <head>Collection</head> ! <p> A collection of data items, typically contained by a programming language object, class, ! structure, or a database record, may be represented in XML Schema using a single model ! group. The individual items held in a collection may appear either as XML element or ! attribute values.</p> ! <example id="eg-simple-collection"> ! <head>Simple Collection</head> ! <eg xml:space="preserve"><![CDATA[ <xs:complexType name="ProductType"> <xs:sequence> <xs:element name="name" type="xs:string"/> ! <xs:element name="shade" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:string" /> + <xs:attribute name="inStock" type="xs:int" /> </xs:complexType> ! ]]></eg> ! </example> ! <p> The collection may be composed using a model group of either:</p> ! <ulist> ! <item> ! <p> ! <code>sequence</code> - the elements are ordered</p> ! </item> ! <item> ! <p> ! <code>all</code> - the elements are unordered</p> ! </item> ! <item> ! <p> ! <code>choice</code> - only one of the elements may be present</p> ! </item> ! </ulist> ! <p>The <code>all</code> model group may appear attractive given programming language ! techniques such as introspection or reflection often return items in a random order. ! However, there are significant restrictions placed upon <code>all</code> types, not least ! an element cannot have a <code>maxOccurs</code> value greater than <code>1</code>. The ! <loc href="http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#cos-nonambig">Unique ! Particle Attribution</loc> (UPA) constraint prevents a model group of <code>all</code> ! from being extended, either by containing an <code>any</code> element wildcard, being ! incorporated in a substitution group or derived using extension or restriction. </p> ! </div2> ! <div2 id="Collection-Extending-Attributes"> ! <head>Extending A Collection With Attributes</head> ! <p>A collection may be made open to extension by the addition of attributes using the ! <code>anyAttribute</code> construct.</p> ! <example id="eg-extended-collection-attributes"> ! <head>Extending a Collection with Attributes</head> ! <eg xml:space="preserve"><![CDATA[ <xs:complexType name="ProductType"> <xs:sequence> ! <xs:element name="name" type="xs:string" /> ! <xs:element name="shade" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:string" /> ! <xs:anyAttribute namespace="##any" processContents="lax"/> </xs:complexType> ! ]]></eg> ! </example> ! <p>The <code>namespace</code> value will typically either be: <ulist> ! <item> ! <p> ! <code>##targetNamespace</code> - the additional items will appear in the same ! namespace </p> ! </item> ! <item> ! <p> ! <code>##other</code> - the additional items may appear in a different namespace </p> ! </item> ! <item> ! <p> ! <code>##any</code> - the additional items may appear in any namespace</p> ! </item> ! </ulist> ! </p> ! <p>The <code>processContents</code> value of <code>lax</code> is typically used to indicate ! that additional items are unlikely to be known to the schema, this is a common case when ! evolving a schema to another version.</p> </div2> + <div2 id="Collection-Extending-Elements"> + <head>Extending A Collection With Elements</head> + <example id="eg-extended-collection-elements"> + <head>Extending a Collection with Elements in Another Namespace</head> + <eg xml:space="preserve"><![CDATA[ + <xs:complexType name="ProductType"> + <xs:sequence> + <xs:element name="name" type="xs:string" /> + <xs:element name="shade" type="xs:string" /> + <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + ]]></eg> + </example> + <p> An <code>any</code> construct with a namespace of <code>##other</code> may directly + follow an optional element. </p> + <example id="eg-extended-collection-other"> + <head>Extending a Collection with Elements After an Optional Element</head> + <eg xml:space="preserve"><![CDATA[ + <xs:complexType name="ProductType"> + <xs:sequence> + <xs:element name="name" type="xs:string" /> + <xs:element name="shade" type="xs:string" /> + <xs:element name="nickName" type="xs:string" minOccurs="0"/> + <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + ]]></eg> + </example> + <p>The UPA constraint prevents an <code>any</code> wildcard with a <code>namespace</code> + value of <code>any</code> or <code>targetNamespace</code> to follow an element with a + <code>minOccurs</code> value of <code>0</code>. In the case where a collection may be + extended within the same namespace, an optional wrapper element may be used to contain the + <code>any</code> wildcard.</p> + <example id="eg-extended-collection-wrapper"> + <head>Extending a Collection within a Single Namespace</head> + <eg xml:space="preserve"><![CDATA[ + <xs:complexType name="CustomerType"> + <xs:sequence> + <xs:element name="firstName" type="xs:string" /> + <xs:element name="lastName" type="xs:string" /> + <xs:element name="extension" type="tns:CustomerExtensionType" minOccurs="0" /> + </xs:sequence> + <xs:anyAttribute/> + </xs:complexType> + <xs:complexType name="CustomerExtensionType"> + <xs:sequence> + <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" + namespace="##targetNamespace"/> + </xs:sequence> + </xs:complexType> + ]]></eg> + <p>Optional elements may be added to the CustomerExtenstionType whilst remaining + compatible with previous versions of the schema:</p> + <eg xml:space="preserve"><![CDATA[ + <xs:complexType name="CustomerExtensionType"> + <xs:sequence> + <xs:element name="middleName" type="xs:string" minOccurs="0" /> + <xs:element name="title" type="xs:string" minOccurs="0" /> + <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" + namespace="##targetNamespace"/> + </xs:sequence> + </xs:complexType> + ]]></eg> + </example> + <p>Note that the 'any' element wildcard cannot be not be used within an <code>all</code> + model group.</p> + </div2> + <div2 id="Inheritence"> + <head>Inheritance</head> + <ednote> + <name>PaulD</name> + <date>2005-07-14</date> + <edtext>Examples of extending a collection into another namespace as for a class being + extended into another package</edtext> + </ednote> + </div2> <div2 id="Vector"> ! <head>Vector</head> ! <p> A vector is an ordered sequence of repeated items of the same data type. This is a very ! common construct in programming languages appearing as an array or list. Some tools which ! generate schemas from a model may elect to give each vector a dedicated type including a ! wrapper element.</p> ! <example id="eg-wrapped-vector"> ! <head>Wrapped Vector</head> ! <eg xml:space="preserve"><![CDATA[ ! <xsd:complexType name="ItemListType"> <xsd:sequence> <xsd:element name="item" type="xsd:string" minOccurs=0 maxOccurs="unbounded"/> ! </xsd:sequence> </xsd:complexType> ! ]]></eg> ! </example> ! <p> However, this may not always be the case, and a collection may contain repeated ! elements.</p> ! <example id="eg-bare-vectors"> ! <head>A Collection of Vectors</head> ! <eg xml:space="preserve"><![CDATA[ ! <xs:complexType name="CustomerType"> ! <xs:sequence> ! <xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> ! <xs:element name="addressLine" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> ! <xs:element name="telephoneNumber" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> ! <xs:sequence> ! </xs:complexType> ! ]]></eg> ! </example> ! <p>A multi-dimensional array may be built by composing collections and vectors which contain ! vectors. More complicated array structures such as a sparse or jagged matrices are beyond ! the scope of this note.</p> </div2> + <div2 id="Map"> + <head>Map</head> + <ednote> + <name>PaulD</name> + <date>2005-07-14</date> + <edtext>This section is work in progress ..</edtext> + </ednote> + <p>A map is an unordered collection of appearing in programming languages as a "hash table", + "dictionary", "associative array", "associative memory", "indexed table", "keyed data", + etc.</p> + <example id="eg-map-simple"> + <head>A Basic Map</head> + <eg xml:space="preserve"><![CDATA[ + <xs:complexType name="CountryCodeMap"> + <xs:all> + <xs:element name="name" type="tns:CountryCodeItem" minOccurs="0" maxOccurs="unbounded"/> + <xs:all> + </xs:complexType> ! <xs:complexType name="CountryCodeMapItem"> ! <xs:sequence> ! <xs:element name="countryName" type="xs:string"/> ! </xs:sequence> ! <xs:attribute type="xs:ID" use="required" /> ! </xs:complexType> ! ]]></eg> ! </example> ! <p/> ! <example id="eg-map-xml-id"> ! <head>Map Keyed Using xml:id</head> ! <eg xml:space="preserve"><![CDATA[ <xs:schema targetNamespace="http://www.w3.org/1998/XML/Namespace"> <xs:attribute name="id" type="xs:ID"/> *************** *** 301,392 **** </xs:schema> ! ]]></eg> ! </example> ! ! <ednote><edtext> ! The xs:unique provides a means of expressing that an element or attribute ! value is unique within a specified set of elements. A selector XPath ! expression defines the set of elements and attributes which constitute ! the context, a second field XPath expression identifies an element or ! attribute which must be unique within the context, e.g.: ! </edtext></ednote> ! ! <example id="eg-map-unique"> ! <head>Map Keyed Using xs:unique</head> ! <eg xml:space="preserve"><![CDATA[ ! <xs:element name="products"> ! <xs:complexType> ! <xs:sequence> ! <xs:element name="product" type="ProductType" ! maxOccurs="unbounded"/> ! </xs:sequence> ! </xs:complexType> ! ! <xs:unique name="product"> ! <xs:selector xpath="product"/> ! <xs:field xpath="@id"/> ! </xs:unique> ! ! </xs:element> ! ! <xs:complexType name="ProductType"> ! <xs:sequence> ! <xs:element name="name" type="xs:string"/> ! <xs:element name="price" type="xs:string"/> ! </xs:sequence> ! <xs:attribute name="id" type="xs:string" /> ! </xs:complexType> ! ]]></eg> ! </example> ! ! <ednote> ! <edtext>xs:key is very similar to xs:unique, but adds a constaint that all ! nodes corresponding to all fields have to be present. Key has been ! designed for use with xs:keyref - similar to ID/IDREF in DTD with ! the difference that the uniqueness is within a XPath defined scope. ! xs:key is therefore preferable to xs:unique when describing a key.</edtext></ednote> ! ! <ednote><edtext> ! - ID is an NCName datatype. A raw number such as an ISBN such as ! "0123456789" could be represented as "isbn_0123456789", more ! complex types such as a Java object will require a hashed key ! value. ! - ID is an NCName datatype. A raw number such as an ISBN such as ! ! - ID has to be unique within the entire document. A context specific ! prefix could added to the front of each key. ! ! - there may be more than one ID, xs:unique or xs:key value for ! a repeated element. Rules as to which element/attribute should be ! used as the primary key could be provided, or be left undefined. ! ! - ID's are presented in the PSVI ID/IDREF table. May assist processing. ! ! - xs:unique and xs:key are more explicit in which containing elements ! form the map. ! ! - xs:unique and xs:key allow multiple fields to form a composite key ! ! - xs:unique and xs:key are complex and not well supported by current ! implementations ! ! - not all schema languages have a means of expressing a uniqueness ! constraint. xs:unique and xs:key don't map well to Relax NG. ! </edtext></ednote> ! ! <ednote><edtext> ! I'd suggest using the simple xml:id as a good mechanism for generating ! a map from code with the caveats on the key having to be NCName as well ! as document wide unique. ! ! I suggest we offer xml:id, xs:ID, xs:unique and xs:key as patterns for ! recognising a map when binding schema to code. ! </edtext></ednote> ! </div2> - - - - </div1> <div1 id="normative-references"> --- 427,433 ---- </xs:schema> ! ]]></eg> ! </example> </div2> </div1> <div1 id="normative-references"> Index: xml-schema-patterns.html =================================================================== RCS file: /sources/public/2002/ws/desc/schema-patterns/xml-schema-patterns.html,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** xml-schema-patterns.html 1 Jul 2005 15:32:17 -0000 1.2 --- xml-schema-patterns.html 14 Jul 2005 14:32:30 -0000 1.3 *************** *** 89,98 **** described are intended to be independent of any particular programming language or database or modelling environment.</p> - <p>Authors of tools which map or bind data structures to XML may - find these simple patterns useful in facilitating the mapping of - commonplace constructs to and from XML.</p> - <p>Authors of XML Schema 1.0 documents may also find these patterns - useful in providing a good user experience for consumers using data - mapping and binding tools.</p> </div> <div> --- 89,92 ---- *************** *** 100,107 **** <p><strong>This document is an editors' copy that has no official standing.</strong></p> ! <p><em>The intention is that this document will be published as a ! Web Services Description Working Group Note, although the Working ! Group has show interest in this work taking place, the Working ! Group has yet to review or approve this document.</em></p> </div> <div class="toc"> --- 94,113 ---- <p><strong>This document is an editors' copy that has no official standing.</strong></p> ! <p>This origin if this document stems from discussions surrounding ! a set of example XML Schema patterns submitted as examples for the ! <a href="http://www.w3.org/TR/wsdl20-primer/">WSDL 2.0 Primer</a> ! [<a href= ! "http://lists.w3.org/Archives/Public/www-ws-desc/2004May/0007.html">http://lists.w3.org/Archives/Public/www-ws-desc/2004May/0007.html</a>].</p> ! <p>However, as a result of discussions during the <a href= ! "http://www.w3.org/2005/03/xml-schema-user-program.html">W3C ! Workshop on XML Schema 1.0 User Experiences</a>, the W3C may form a ! dedicated Working Group to <em>develop a set of patterns for common ! data structures of XML Schema for the purpose of simplifying the ! mapping of XML Schemas into programming language structures</em> ! [<a href= ! "http://lists.w3.org/Archives/Public/www-ws/2005Jul/0000.html">http://lists.w3.org/Archives/Public/www-ws/2005Jul/0000.html</a>]. ! This note may provide useful input to such a Working Group.</p> ! <p><em>The WSD Working Group has yet to review or approve this ! document.</em></p> </div> <div class="toc"> *************** *** 110,120 **** 1.1 <a href="#notational">Notational Conventions</a><br /> ! 2 <a href="#Data-Structures">Common Data Structures</a><br /> ! 2.1 <a href="#Enumerated">Enumerated Types</a><br /> ! 2.2 <a href= ! "#Collection">Collections</a><br /> ! 2.3 <a href="#Vector">Vectors</a><br /> ! 2.4 <a href="#Maps">Maps</a><br /> 3 <a href="#normative-references">Normative References</a><br /> 4 <a href="#informative-references">Informative --- 116,139 ---- 1.1 <a href="#notational">Notational Conventions</a><br /> ! 2 <a href="#Data-Structures">Patterns for Common Data ! Structures</a><br /> ! 2.1 <a href="#Naming">Naming Types</a><br /> ! 2.2 <a href="#Enumerated">Enumerated ! Type</a><br /> ! 2.3 <a href="#Enumerated-Open">Open ! Enumerated Type</a><br /> ! 2.4 <a href= ! "#Collection">Collection</a><br /> ! 2.5 <a href= ! "#Collection-Extending-Attributes">Extending A Collection With ! Attributes</a><br /> ! 2.6 <a href= ! "#Collection-Extending-Elements">Extending A Collection With ! Elements</a><br /> ! 2.7 <a href= ! "#Inheritence">Inheritance</a><br /> ! 2.8 <a href="#Vector">Vector</a><br /> ! 2.9 <a href="#Map">Map</a><br /> 3 <a href="#normative-references">Normative References</a><br /> 4 <a href="#informative-references">Informative *************** *** 128,143 **** <h2><a name="introduction" id="introduction"></a>1 Introduction</h2> ! <table border="1" summary="Editorial note"> ! <tr> ! <td align="left" valign="top" width="50%"><b>Editorial ! note</b></td> ! <td align="right" valign="top" width="50%"> </td> ! </tr> ! <tr> ! <td colspan="2" align="left" valign="top">Explanation of how schema ! may be used as a description language, as well as for validation. ! Reference to WSDL which uses XML Schema for such a purpose</td> ! </tr> ! </table> <div class="div2"> <h3><a name="notational" id="notational"></a>1.1 Notational --- 147,169 ---- <h2><a name="introduction" id="introduction"></a>1 Introduction</h2> ! <p>This note provides a set of example XML Schema structures ! <a href="#XMLSchemaP1">[XML Schema: Structures]</a> and types ! <a href="#XMLSchemaP2">[XML Schema: Datatypes]</a> which may be ! used to exchange commonly used data structures in the form of an ! XML document.</p> ! <p>Authors of tools which map or bind data structures to XML may ! find these patterns useful to represent simple and common place ! constructs. Recognising these patterns and presenting them in terms ! most appropriate to the specific language, database or environment ! may preserve such data structures across boundaries, as well as ! providing an improved <em>user experience</em> when using data ! mapping and binding tools.</p> ! <p>Authors of XML Schema 1.0 documents may find these patterns ! useful in providing a better <em>user experience</em> for consumers ! of their schemas using data mapping and binding tools.</p> ! <p>It is not intended that these constructs should constrain the ! use of the XML Schema Recommendation. A processor using these ! constructs to map data structures should continue to support the ! whole of the XML Schema Recommendation.</p> <div class="div2"> <h3><a name="notational" id="notational"></a>1.1 Notational *************** *** 190,201 **** </div> <div class="div1"> ! <h2><a name="Data-Structures" id="Data-Structures"></a>2 Common ! Data Structures</h2> <div class="div2"> ! <h3><a name="Enumerated" id="Enumerated"></a>2.1 Enumerated ! Types</h3> <div class="exampleOuter"> ! <div class="exampleHeader"><a name="eg-closed-enum" id= ! "eg-closed-enum"></a>Example 1: Closed Enumerated Type</div> <div class="exampleInner"> <pre> --- 216,240 ---- </div> <div class="div1"> ! <h2><a name="Data-Structures" id="Data-Structures"></a>2 Patterns ! for Common Data Structures</h2> <div class="div2"> ! <h3><a name="Naming" id="Naming"></a>2.1 Naming Types</h3> ! <p>Giving each data structure an individual type, following the ! so-called "venetian blind" schema authoring style, simplifies ! mapping to and from a data model.</p> ! <p>The name of a schema type, attribute or element may be any valid ! XML non-colonized name including names which may be reserved or not ! directly representable in some programming languages, such as ! "object", "static", "final", "class", "Customer-Profile", etc.</p> ! </div> ! <div class="div2"> ! <h3><a name="Enumerated" id="Enumerated"></a>2.2 Enumerated ! Type</h3> ! <p>The XML Schema enumerated type provides a useful mechanism for ! expressing a controlled vocabulary for an element or attribute ! value.</p> <div class="exampleOuter"> ! <div class="exampleHeader"><a name="eg-enum" id= ! "eg-enum"></a>Example 1: Enumerated Type</div> <div class="exampleInner"> <pre> *************** *** 210,215 **** --- 249,262 ---- </xs:restriction> </xs:simpleType> + </pre></div> </div> + </div> + <div class="div2"> + <h3><a name="Enumerated-Open" id="Enumerated-Open"></a>2.3 Open + Enumerated Type</h3> + <p>Reusing the enumeration in a union with the base type or in + combination with other enumerations may be used to express a + vocabulary open to additional values.</p> <div class="exampleOuter"> <div class="exampleHeader"><a name="eg-open-enum" id= *************** *** 217,250 **** <div class="exampleInner"> <pre> ! <xs:simpleType name='Fruit' > <xs:restriction base='xs:string' > ! <xs:enumeration value='Apple' /> ! <xs:enumeration value='Pear' /> ! <xs:enumeration value='Banana' /> </xs:restriction> </xs:simpleType> ! <xs:simpleType name='Pudding' > ! <xs:union memberTypes='tns:Fruit xs:string' /> </xs:simpleType> </pre></div> </div> </div> <div class="div2"> ! <h3><a name="Collection" id="Collection"></a>2.2 Collections</h3> ! <table border="1" summary="Editorial note"> ! <tr> ! <td align="left" valign="top" width="50%"><b>Editorial ! note</b></td> ! <td align="right" valign="top" width="50%"> </td> ! </tr> ! <tr> ! <td colspan="2" align="left" valign="top">A collection of data ! items (an object, class, structure, record etc) is best represented ! as a complexType with the individual items as elements and/or ! attributes. Sadly it needs saying that the compositors "sequence", ! "all" *and* "choice" should be supported.</td> ! </tr> ! </table> <div class="exampleOuter"> <div class="exampleHeader"><a name="eg-simple-collection" id= --- 264,298 ---- <div class="exampleInner"> <pre> ! <xs:simpleType name='AppleVariety' > <xs:restriction base='xs:string' > ! <xs:enumeration value='Braeburn' /> ! <xs:enumeration value='Cox' /> ! <xs:enumeration value='Egremont Russet' /> ! <xs:enumeration value='Granny Smith' /> </xs:restriction> </xs:simpleType> ! <xs:simpleType name='PlumVariety' > ! <xs:restriction base='xs:string' > ! <xs:enumeration value='Damson' /> ! <xs:enumeration value='Greengage' /> ! <xs:enumeration value='Victoria' /> ! </xs:restriction> ! </xs:simpleType> ! ! <xs:simpleType name='FruitVariety' > ! <xs:union memberTypes='tns:AppleVariety tns:PlumVariety xs:string' /> </xs:simpleType> + </pre></div> </div> </div> <div class="div2"> ! <h3><a name="Collection" id="Collection"></a>2.4 Collection</h3> ! <p>A collection of data items, typically contained by a programming ! language object, class, structure, or a database record, may be ! represented in XML Schema using a single model group. The ! individual items held in a collection may appear either as XML ! element or attribute values.</p> <div class="exampleOuter"> <div class="exampleHeader"><a name="eg-simple-collection" id= *************** *** 255,403 **** <xs:sequence> <xs:element name="name" type="xs:string"/> ! <xs:element name="colour" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:string" /> </xs:complexType> </pre></div> </div> ! <table border="1" summary="Editorial note"> ! <tr> ! <td align="left" valign="top" width="50%"><b>Editorial ! note</b></td> ! <td align="right" valign="top" width="50%"> </td> ! </tr> ! <tr> ! <td colspan="2" align="left" valign="top">Explicit (active) ! extensibility of a collection may be expressed using 'any' and ! 'anyAttribute' as in the following example adapted from the draft ! TAG finding on extensibility and versioning[2]:</td> ! </tr> ! </table> <div class="exampleOuter"> ! <div class="exampleHeader"><a name="eg-extended-collection" id= ! "eg-extended-collection"></a>Example 4: Extending a ! Collection</div> <div class="exampleInner"> <pre> <xs:complexType name="ProductType"> <xs:sequence> ! <xs:element name="name" type="xs:string" ! minOccurs="1" maxOccurs="1"/> ! <xs:element name="colour" type="xs:string"/> ! <xs:any processContents="lax" ! minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="id" type="xs:string" /> ! <xs:anyAttribute/> </xs:complexType> </pre></div> </div> ! <table border="1" summary="Editorial note"> ! <tr> ! <td align="left" valign="top" width="50%"><b>Editorial ! note</b></td> ! <td align="right" valign="top" width="50%"> </td> ! </tr> ! <tr> ! <td colspan="2" align="left" valign="top">The 'any' wildcard is ! only deterministic when applied to the end of a 'sequence' - ! determinism being particularly important when generating messages ! from a schema definition. Again it needs saying that tools should ! support the 'namespace' attribute including the '##any', '##other' ! and '#</td> ! </tr> ! </table> ! <table border="1" summary="Editorial note"> <tr> ! <td align="left" valign="top" width="50%"><b>Editorial ! note</b></td> ! <td align="right" valign="top" width="50%"> </td> </tr> <tr> ! <td colspan="2" align="left" valign="top">Add Dare Obasanjo's ! pattern for subverting greedy 'any'.</td> </tr> </table> </div> <div class="div2"> ! <h3><a name="Vector" id="Vector"></a>2.3 Vectors</h3> ! <p>A vector is an ordered sequence of items of the same data type. ! This is a very common construct in programming languages appearing ! as an array or list. Multi-dimensional arrays may be built by ! composing vectors within vectors. Formalising more complex ! constructs such as sparse or jagged matrices are beyond the scope ! of these examples.</p> <div class="exampleOuter"> <div class="exampleHeader"><a name="eg-wrapped-vector" id= ! "eg-wrapped-vector"></a>Example 5: Wrapped Vector</div> <div class="exampleInner"> <pre> ! <xsd:complexType name="ItemList"> <xsd:sequence> <xsd:element name="item" type="xsd:string" minOccurs=0 maxOccurs="unbounded"/> ! </xsd:sequence> </xsd:complexType> </pre></div> </div> <div class="exampleOuter"> <div class="exampleHeader"><a name="eg-bare-vectors" id= ! "eg-bare-vectors"></a>Example 6: Bare Vector</div> <div class="exampleInner"> <pre> ! <xs:complexType name="Address"> ! <xs:sequence> ! <xs:element name="lines" type="xs:string" maxOccurs="unbounded"/> ! <xs:element name="telnos" type="xs:string" maxOccurs="unbounded"/> ! <xs:sequence> ! </xs:complexType> </pre></div> </div> </div> <div class="div2"> ! <h3><a name="Maps" id="Maps"></a>2.4 Maps</h3> ! <table border="1" summary="Editorial note"> ! <tr> ! <td align="left" valign="top" width="50%"><b>Editorial ! note</b></td> ! <td align="right" valign="top" width="50%"> </td> ! </tr> ! <tr> ! <td colspan="2" align="left" valign="top">xs:ID is similar to the ! DTD ID type with the following properties: - the type has the same ! lexical space as xs:NCName - the ID may be an attribute or an ! element - the ID value must be unique with the document - there may ! be one or more ID's associated with an element</td> ! </tr> ! </table> ! <table border="1" summary="Editorial note"> ! <tr> ! <td align="left" valign="top" width="50%"><b>Editorial ! note</b></td> ! <td align="right" valign="top" width="50%"> </td> ! </tr> ! <tr> ! <td colspan="2" align="left" valign="top">The PSVI set contains a ! ID/IDREF table[7] which is an index pointing to nodes with an ! included xs:ID element/attribute.</td> ! </tr> ! </table> ! <table border="1" summary="Editorial note"> <tr> ! <td align="left" valign="top" width="50%"><b>Editorial ! note</b></td> ! <td align="right" valign="top" width="50%"> </td> </tr> <tr> ! <td colspan="2" align="left" valign="top">The new xml:id[8] ! attribute from the XML Base WG offers an neat way of expressing an ! ID value for an element targeted at recipients who may not have ! access to a schema. A so called 'disengaged' agent may easily more ! recognise a map from a document containing xml:id attributes and ! present the repeated element as an associative array, e.g:</td> </tr> </table> <div class="exampleOuter"> <div class="exampleHeader"><a name="eg-map-xml-id" id= ! "eg-map-xml-id"></a>Example 7: Map Keyed Using xml:id</div> <div class="exampleInner"> <pre> --- 303,569 ---- <xs:sequence> <xs:element name="name" type="xs:string"/> ! <xs:element name="shade" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:string" /> + <xs:attribute name="inStock" type="xs:int" /> </xs:complexType> + </pre></div> </div> ! <p>The collection may be composed using a model group of ! either:</p> ! <ul> ! <li> ! <p><code>sequence</code> - the elements are ordered</p> ! </li> ! <li> ! <p><code>all</code> - the elements are unordered</p> ! </li> ! <li> ! <p><code>choice</code> - only one of the elements may be ! present</p> ! </li> ! </ul> ! <p>The <code>all</code> model group may appear attractive given ! programming language techniques such as introspection or reflection ! often return items in a random order. However, there are ! significant restrictions placed upon <code>all</code> types, not ! least an element cannot have a <code>maxOccurs</code> value greater ! than <code>1</code>. The <a href= ! "http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#cos-nonambig">Unique ! Particle Attribution</a> (UPA) constraint prevents a model group of ! <code>all</code> from being extended, either by containing an ! <code>any</code> element wildcard, being incorporated in a ! substitution group or derived using extension or restriction.</p> ! </div> ! <div class="div2"> ! <h3><a name="Collection-Extending-Attributes" id= ! "Collection-Extending-Attributes"></a>2.5 Extending A Collection ! With Attributes</h3> ! <p>A collection may be made open to extension by the addition of ! attributes using the <code>anyAttribute</code> construct.</p> <div class="exampleOuter"> ! <div class="exampleHeader"><a name= ! "eg-extended-collection-attributes" id= ! "eg-extended-collection-attributes"></a>Example 4: Extending a ! Collection with Attributes</div> <div class="exampleInner"> <pre> <xs:complexType name="ProductType"> <xs:sequence> ! <xs:element name="name" type="xs:string" /> ! <xs:element name="shade" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:string" /> ! <xs:anyAttribute namespace="##any" processContents="lax"/> </xs:complexType> + </pre></div> </div> ! <p>The <code>namespace</code> value will typically either be:</p> ! <ul> ! <li> ! <p><code>##targetNamespace</code> - the additional items will ! appear in the same namespace</p> ! </li> ! <li> ! <p><code>##other</code> - the additional items may appear in a ! different namespace</p> ! </li> ! <li> ! <p><code>##any</code> - the additional items may appear in any ! namespace</p> ! </li> ! </ul> ! <p>The <code>processContents</code> value of <code>lax</code> is ! typically used to indicate that additional items are unlikely to be ! known to the schema, this is a common case when evolving a schema ! to another version.</p> ! </div> ! <div class="div2"> ! <h3><a name="Collection-Extending-Elements" id= ! "Collection-Extending-Elements"></a>2.6 Extending A Collection With ! Elements</h3> ! <div class="exampleOuter"> ! <div class="exampleHeader"><a name= ! "eg-extended-collection-elements" id= ! "eg-extended-collection-elements"></a>Example 5: Extending a ! Collection with Elements in Another Namespace</div> ! <div class="exampleInner"> ! <pre> ! <xs:complexType name="ProductType"> ! <xs:sequence> ! <xs:element name="name" type="xs:string" /> ! <xs:element name="shade" type="xs:string" /> ! <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> ! </xs:sequence> ! </xs:complexType> ! ! </pre></div> ! </div> ! <p>An <code>any</code> construct with a namespace of ! <code>##other</code> may directly follow an optional element.</p> ! <div class="exampleOuter"> ! <div class="exampleHeader"><a name="eg-extended-collection-other" ! id="eg-extended-collection-other"></a>Example 6: Extending a ! Collection with Elements After an Optional Element</div> ! <div class="exampleInner"> ! <pre> ! <xs:complexType name="ProductType"> ! <xs:sequence> ! <xs:element name="name" type="xs:string" /> ! <xs:element name="shade" type="xs:string" /> ! <xs:element name="nickName" type="xs:string" minOccurs="0"/> ! <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> ! </xs:sequence> ! </xs:complexType> ! ! </pre></div> ! </div> ! <p>The UPA constraint prevents an <code>any</code> wildcard with a ! <code>namespace</code> value of <code>any</code> or ! <code>targetNamespace</code> to follow an element with a ! <code>minOccurs</code> value of <code>0</code>. In the case where a ! collection may be extended within the same namespace, an optional ! wrapper element may be used to contain the <code>any</code> ! wildcard.</p> ! <div class="exampleOuter"> ! <div class="exampleHeader"><a name="eg-extended-collection-wrapper" ! id="eg-extended-collection-wrapper"></a>Example 7: Extending a ! Collection within a Single Namespace</div> ! <div class="exampleInner"> ! <pre> ! <xs:complexType name="CustomerType"> ! <xs:sequence> ! <xs:element name="firstName" type="xs:string" /> ! <xs:element name="lastName" type="xs:string" /> ! <xs:element name="extension" type="tns:CustomerExtensionType" minOccurs="0" /> ! </xs:sequence> ! <xs:anyAttribute/> ! </xs:complexType> ! ! <xs:complexType name="CustomerExtensionType"> ! <xs:sequence> ! <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" ! namespace="##targetNamespace"/> ! </xs:sequence> ! </xs:complexType> ! ! </pre></div> ! <p>Optional elements may be added to the CustomerExtenstionType ! whilst remaining compatible with previous versions of the ! schema:</p> ! <div class="exampleInner"> ! <pre> ! <xs:complexType name="CustomerExtensionType"> ! <xs:sequence> ! <xs:element name="middleName" type="xs:string" minOccurs="0" /> ! <xs:element name="title" type="xs:string" minOccurs="0" /> ! <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" ! namespace="##targetNamespace"/> ! </xs:sequence> ! </xs:complexType> ! ! </pre></div> ! </div> ! <p>Note that the 'any' element wildcard cannot be not be used ! within an <code>all</code> model group.</p> ! </div> ! <div class="div2"> ! <h3><a name="Inheritence" id="Inheritence"></a>2.7 Inheritance</h3> ! <table border="1" summary="Editorial note: PaulD"> <tr> ! <td align="left" valign="top" width="50%"><b>Editorial note: ! PaulD</b></td> ! <td align="right" valign="top" width="50%">2005-07-14</td> </tr> <tr> ! <td colspan="2" align="left" valign="top">Examples of extending a ! collection into another namespace as for a class being extended ! into another package</td> </tr> </table> </div> <div class="div2"> ! <h3><a name="Vector" id="Vector"></a>2.8 Vector</h3> ! <p>A vector is an ordered sequence of repeated items of the same ! data type. This is a very common construct in programming languages ! appearing as an array or list. Some tools which generate schemas ! from a model may elect to give each vector a dedicated type ! including a wrapper element.</p> <div class="exampleOuter"> <div class="exampleHeader"><a name="eg-wrapped-vector" id= ! "eg-wrapped-vector"></a>Example 8: Wrapped Vector</div> <div class="exampleInner"> <pre> ! <xsd:complexType name="ItemListType"> <xsd:sequence> <xsd:element name="item" type="xsd:string" minOccurs=0 maxOccurs="unbounded"/> ! </xsd:sequence> </xsd:complexType> + </pre></div> </div> + <p>However, this may not always be the case, and a collection may + contain repeated elements.</p> <div class="exampleOuter"> <div class="exampleHeader"><a name="eg-bare-vectors" id= ! "eg-bare-vectors"></a>Example 9: A Collection of Vectors</div> <div class="exampleInner"> <pre> ! <xs:complexType name="CustomerType"> ! <xs:sequence> ! <xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> ! <xs:element name="addressLine" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> ! <xs:element name="telephoneNumber" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> ! <xs:sequence> ! </xs:complexType> ! </pre></div> </div> + <p>A multi-dimensional array may be built by composing collections + and vectors which contain vectors. More complicated array + structures such as a sparse or jagged matrices are beyond the scope + of this note.</p> </div> <div class="div2"> ! <h3><a name="Map" id="Map"></a>2.9 Map</h3> ! <table border="1" summary="Editorial note: PaulD"> <tr> ! <td align="left" valign="top" width="50%"><b>Editorial note: ! PaulD</b></td> ! <td align="right" valign="top" width="50%">2005-07-14</td> </tr> <tr> ! <td colspan="2" align="left" valign="top">This section is work in ! progress ..</td> </tr> </table> + <p>A map is an unordered collection of appearing in programming + languages as a "hash table", "dictionary", "associative array", + "associative memory", "indexed table", "keyed data", etc.</p> + <div class="exampleOuter"> + <div class="exampleHeader"><a name="eg-map-simple" id= + "eg-map-simple"></a>Example 10: A Basic Map</div> + <div class="exampleInner"> + <pre> + <xs:complexType name="CountryCodeMap"> + <xs:all> + <xs:element name="name" type="tns:CountryCodeItem" minOccurs="0" maxOccurs="unbounded"/> + <xs:all> + </xs:complexType> + + <xs:complexType name="CountryCodeMapItem"> + <xs:sequence> + <xs:element name="countryName" type="xs:string"/> + </xs:sequence> + <xs:attribute type="xs:ID" use="required" /> + </xs:complexType> + + </pre></div> + </div> <div class="exampleOuter"> <div class="exampleHeader"><a name="eg-map-xml-id" id= ! "eg-map-xml-id"></a>Example 11: Map Keyed Using xml:id</div> <div class="exampleInner"> <pre> *************** *** 418,522 **** </xs:schema> </pre></div> </div> - <table border="1" summary="Editorial note"> - <tr> - <td align="left" valign="top" width="50%"><b>Editorial - note</b></td> - <td align="right" valign="top" width="50%"> </td> - </tr> - <tr> - <td colspan="2" align="left" valign="top">The xs:unique provides a - means of expressing that an element or attribute value is unique - within a specified set of elements. A selector XPath expression - defines the set of elements and attributes which constitute the - context, a second field XPath expression identifies an element or - attribute which must be unique within the context, e.g.:</td> - </tr> - </table> - <div class="exampleOuter"> - <div class="exampleHeader"><a name="eg-map-unique" id= - "eg-map-unique"></a>Example 8: Map Keyed Using xs:unique</div> - <div class="exampleInner"> - <pre> - <xs:element name="products"> - <xs:complexType> - <xs:sequence> - <xs:element name="product" type="ProductType" - maxOccurs="unbounded"/> - </xs:sequence> - </xs:complexType> - - <xs:unique name="product"> - <xs:selector xpath="product"/> - <xs:field xpath="@id"/> - </xs:unique> - - </xs:element> - - <xs:complexType name="ProductType"> - <xs:sequence> - <xs:element name="name" type="xs:string"/> - <xs:element name="price" type="xs:string"/> - </xs:sequence> - <xs:attribute name="id" type="xs:string" /> - </xs:complexType> - </pre></div> - </div> - <table border="1" summary="Editorial note"> - <tr> - <td align="left" valign="top" width="50%"><b>Editorial - note</b></td> - <td align="right" valign="top" width="50%"> </td> - </tr> - <tr> - <td colspan="2" align="left" valign="top">xs:key is very similar to - xs:unique, but adds a constaint that all nodes corresponding to all - fields have to be present. Key has been designed for use with - xs:keyref - similar to ID/IDREF in DTD with the difference that the - uniqueness is within a XPath defined scope. xs:key is therefore - preferable to xs:unique when describing a key.</td> - </tr> - </table> - <table border="1" summary="Editorial note"> - <tr> - <td align="left" valign="top" width="50%"><b>Editorial - note</b></td> - <td align="right" valign="top" width="50%"> </td> - </tr> - <tr> - <td colspan="2" align="left" valign="top">- ID is an NCName - datatype. A raw number such as an ISBN such as "0123456789" could - be represented as "isbn_0123456789", more complex types such as a - Java object will require a hashed key value. - ID is an NCName - datatype. A raw number such as an ISBN such as - ID has to be - unique within the entire document. A context specific prefix could - added to the front of each key. - there may be more than one ID, - xs:unique or xs:key value for a repeated element. Rules as to which - element/attribute should be used as the primary key could be - provided, or be left undefined. - ID's are presented in the PSVI - ID/IDREF table. May assist processing. - xs:unique and xs:key are - more explicit in which containing elements form the map. - - xs:unique and xs:key allow multiple fields to form a composite key - - xs:unique and xs:key are complex and not well supported by - current implementations - not all schema languages have a means of - expressing a uniqueness constraint. xs:unique and xs:key don't map - well to Relax NG.</td> - </tr> - </table> - <table border="1" summary="Editorial note"> - <tr> - <td align="left" valign="top" width="50%"><b>Editorial - note</b></td> - <td align="right" valign="top" width="50%"> </td> - </tr> - <tr> - <td colspan="2" align="left" valign="top">I'd suggest using the - simple xml:id as a good mechanism for generating a map from code - with the caveats on the key having to be NCName as well as document - wide unique. I suggest we offer xml:id, xs:ID, xs:unique and xs:key - as patterns for recognising a map when binding schema to code.</td> - </tr> - </table> </div> </div> --- 584,590 ---- </xs:schema> + </pre></div> </div> </div> </div>
Received on Thursday, 14 July 2005 14:32:44 UTC