Atom example

From W3C Wiki
Jump to: navigation, search

Atom Example for xsi:type Alias

Overview

In Atom (RFC 4287) there are several constructs where the content of the element is controlled by an attribute named 'type'. In most cases, these rules apply:

  1. If the value of the 'type' attribute is 'text', the content typed as xs:string
  2. If the value of the 'type' attribute is 'html', the content typed as xs:string
  3. If the value of the 'type' attribute is 'xhtml', the element contains one XHTML div element.
  4. If the value of the 'type' attribute is 'text/xml' (or other XML mime types), the element contains one XML element.
  5. If the value of the 'type' attribute is 'application/*' or "image/*", the content is typed as xs:base64Binary

In the case of the [atom:]content element, if the src attribute is present (which is a URI), the element must be empty.

Typing Content Using an xsi:type Alias

The proposal is to allow schema-defined mappings between attribute values and type names that mimic the functionality of [xsi:]type. The effect of this is to implicitly "add" an [xsi:]type attribute based on the value of a attribute (e.g. the 'type' attribute).

To handle the simple cases of a fixed enumeration of types, the following is proposed:


<xs:element name="summary" type='xs:TextBaseType'>
   <xs:when test="@type='text'" type='my:TextContent'/>
   <xs:when test="@type='html'" type='my:TextContent'/>
   <xs:when test="@type='xhtml'" type='my:XHTMLContent'/>
   <xs:when test="@type='xml'" type='my:XMLContent'/>
   <xs:when test="@type='image/jpeg'" type='my:BinaryContent'/>
    ... etc. ...
</xs:element>

<xs:complexType name="TextContent">...</xs:complexType>
... etc. ....


For Atom, we really want to have expressions for the mapping as we don't necessarily want to enumerate all the application or image mime types:


<xs:element name="summary" type='xs:TextBaseType'>
   <xs:when test="@type='text'" type='my:TextContent'/>
   <xs:when test="@type='html'" type='my:TextContent'/>
   <xs:when test="@type='xhtml'" type='my:XHTMLContent'/>
   <xs:when test="@type='xml'" type='my:XMLContent'/>
   <xs:when test="matches(@type,'^image/.*')" type='my:BinaryContent'/>
   <xs:when test="matches(@type,'^application/.*')" type='my:BinaryContent'/>
</xs:element>

<xs:complexType name="TextContent">...</xs:complexType>
... etc. ....


To begin with, we'd only allow attributes to be tested. The expressions would be tested in document order and the result would be a value for [xsi:]type and all the same rules for restriction/extension via xsi:type apply. That means that the type referenced on the [xs:]when element needs to restrict/extend type referenced on the [xs:]element element.

Unresolved

While this handles the assignment of type based on the type value, it does not handle the condition that if the 'src' attribute is present on the [atom:]content element, the element must be empty.