χίμαιραλ (chimeral) - the Chimera Language

This Version: V 0.3 (29th February 2012)

Previous Version: http://χίμαιραλ.com/0/2/

Latest Version: http://χίμαιραλ.com

This namespace: http://χίμαιραλ.com#

Editor:

About this page

This page is the home page of the χίμαιραλ (chimeral) project and the documentation of the http://χίμαιραλ.com# XML namespace.

The goal of χίμαιραλ (chimeral) is to facilitate the use of the XPath/XQuery/XSLT 3.0 data model aka XDM 3.0.

The http://χίμαιραλ.com# XML namespace defines a XML serialization format for XDM 3.0.

The name and the idea of this project comes from the presentation given by Jeni Tennison at XML Prague 2012: I was going to show that XDM is a foundation on which the whole XML ecosystem is built and Jeni, giving her opening keynote just before my presentation explained why we should take care of chimeras, “ugly, foolish or impossible fantasies”. This made me realize that XDM, a data model that aggregates the XML infoset and informations items borrowed to XML Schema and now JSON is a chimera and that some efforts are needed to make it viable!

The http://χίμαιραλ.com# XML namespace is a first step in that direction. By providing a serialization format it gives some reality to the XDM that has been a perfectly abstract concept so far. This serialization format is also useful to manipulate the XDM: the items recently imported into the model such as maps are not always considered as first class citizens by XPath/XQuery/XSLT (you can't apply templates on map items for instance) and this serialization can help do that.

The namespace URI itself (http://χίμαιραλ.com#) is a chimera, composed of letters from two different alphabets and merging concepts from two different civilizations.

Basic Principles

The design goals of this vocabulary are:

The XDM makes a clear distinction between nodes and other item types (atomic values, functions and maps).

Fidelity to the XDM commands that χίμαιραλ keeps this distinction.

When a map entry has a node value, this value is a reference to the node in its full context and the complete document to which the node belongs can be accessed through this node.

To keep this behavior, χίμαιραλ copies the documents that are referenced by nodes in χ:instance elements. Like for XDM, map entries node values are references to the nodes in these instances and to be non intrusive, these references are made using XPath expressions.

Another important property of XDM is the lightweight character of sequences: sequences are not considered as an item type they are just repetitions of items. Similarly, χίμαιραλ has no sequence elements and sequences are just repetitions of items.

χίμαιραλ does not support functions (yet?) and is thus left with three types of items:

One of the major differences between XDM and χίμαιραλ is a fourth object χ:entry used to contain map entries which have no incarnation in XDM.

Examples

JSON objects

The following JSON object:

{
     "firstName": "John",
     "lastName" : "Smith",
     "age"      : 25,
     "address"  :
     {
         "streetAddress": "21 2nd Street",
         "city"         : "New York",
         "state"        : "NY",
         "postalCode"   : "10021"
     },
     "phoneNumber":
     [
         {
           "type"  : "home",
           "number": "212 555-1234"
         },
         {
           "type"  : "fax",
           "number": "646 555-4567"
         }
     ]
 }

imported into XDM with the parse-json() function gives the following χίμαιραλ serialization:

<?xml version="1.0" encoding="UTF-8"?>
<χ:data-model xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:χ="http://χίμαιραλ.com#">
   <χ:map>
      <χ:entry key="lastName" keyType="string">
         <χ:atomic-value type="string">Smith</χ:atomic-value>
      </χ:entry>
      <χ:entry key="phoneNumber" keyType="string">
         <χ:map>
            <χ:entry key="1" keyType="number">
               <χ:map>
                  <χ:entry key="number" keyType="string">
                     <χ:atomic-value type="string">212 555-1234</χ:atomic-value>
                  </χ:entry>
                  <χ:entry key="type" keyType="string">
                     <χ:atomic-value type="string">home</χ:atomic-value>
                  </χ:entry>
               </χ:map>
            </χ:entry>
            <χ:entry key="2" keyType="number">
               <χ:map>
                  <χ:entry key="number" keyType="string">
                     <χ:atomic-value type="string">646 555-4567</χ:atomic-value>
                  </χ:entry>
                  <χ:entry key="type" keyType="string">
                     <χ:atomic-value type="string">fax</χ:atomic-value>
                  </χ:entry>
               </χ:map>
            </χ:entry>
         </χ:map>
      </χ:entry>
      <χ:entry key="address" keyType="string">
         <χ:map>
            <χ:entry key="streetAddress" keyType="string">
               <χ:atomic-value type="string">21 2nd Street</χ:atomic-value>
            </χ:entry>
            <χ:entry key="postalCode" keyType="string">
               <χ:atomic-value type="string">10021</χ:atomic-value>
            </χ:entry>
            <χ:entry key="state" keyType="string">
               <χ:atomic-value type="string">NY</χ:atomic-value>
            </χ:entry>
            <χ:entry key="city" keyType="string">
               <χ:atomic-value type="string">New York</χ:atomic-value>
            </χ:entry>
         </χ:map>
      </χ:entry>
      <χ:entry key="age" keyType="string">
         <χ:atomic-value type="number">25</χ:atomic-value>
      </χ:entry>
      <χ:entry key="firstName" keyType="string">
         <χ:atomic-value type="string">John</χ:atomic-value>
      </χ:entry>
   </χ:map>
</χ:data-model>

Map representing a RDF triple

The map defined in XSLT as:

        <xsl:variable name="json" select="
            map {
                xs:QName('rdf:subject')   := xs:anyURI('http://www.example.org/index.html'),
                xs:QName('rdf:predicate') := xs:anyURI('http://purl.org/dc/elements/1.1/creator'),
                xs:QName('rdf:object')    := xs:anyURI('http://www.example.org/staffid/85740')
            }
            
            "
            xmlns:rdf="http://example.com/rdf/"/>

gives the following χίμαιραλ serialization:

<?xml version="1.0" encoding="UTF-8"?>
<χ:data-model xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:χ="http://χίμαιραλ.com#">
   <χ:map>
      <χ:entry xmlns:rdf="http://example.com/rdf/"
               key="rdf:subject"
               keyType="xs:QName">
         <χ:atomic-value type="xs:anyURI">http://www.example.org/index.html</χ:atomic-value>
      </χ:entry>
      <χ:entry xmlns:rdf="http://example.com/rdf/"
               key="rdf:predicate"
               keyType="xs:QName">
         <χ:atomic-value type="xs:anyURI">http://purl.org/dc/elements/1.1/creator</χ:atomic-value>
      </χ:entry>
      <χ:entry xmlns:rdf="http://example.com/rdf/" key="rdf:object" keyType="xs:QName">
         <χ:atomic-value type="xs:anyURI">http://www.example.org/staffid/85740</χ:atomic-value>
      </χ:entry>
   </χ:map>
</χ:data-model>

Map with two references to the same document node

The map defined in XSLT as:

        <xsl:variable name="node">
            <node>
                <foo/>
                <bar/>
            </node>
        </xsl:variable>
        <xsl:variable name="json" select="
             map{
                5     := 'foo', 
                'bar' := $node, 
                'bat' := $node
               }"/>

gives the following χίμαιραλ serialization:

<?xml version="1.0" encoding="UTF-8"?>
<χ:data-model xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:χ="http://χίμαιραλ.com#">
   <χ:instance id="d3">
      <node1>
         <foo/>
         <bar/>
      </node1>
      <node2/>
   </χ:instance>
   <χ:map>
      <χ:entry key="5" keyType="number">
         <χ:atomic-value type="string">foo</χ:atomic-value>
      </χ:entry>
      <χ:entry key="bat" keyType="string">
         <χ:node type="document" instance="d3" ref="/"/>
      </χ:entry>
      <χ:entry key="bar" keyType="string">
         <χ:node type="document" instance="d3" ref="/"/>
      </χ:entry>
   </χ:map>
</χ:data-model>

Map with two instances of the same node, atomic values and sequences

The map defined in XSLT as:

       <xsl:variable name="node">
            <node1>
                <foo/>
                <bar/>
            </node1>
            <node2/>
        </xsl:variable>
        <xsl:variable name="json"
            select="
                map{
                    5 := ('foo', 'bar'), 
                    true() :=  false(),
                    'sequence' := ($node, $node/*, 2)
                 }"/>

gives the following χίμαιραλ serialization:

<?xml version="1.0" encoding="UTF-8"?>
<χ:data-model xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:χ="http://χίμαιραλ.com#">
   <χ:instance id="d3">
      <node1>
         <foo/>
         <bar/>
      </node1>
      <node2/>
   </χ:instance>
   <χ:map>
      <χ:entry key="true" keyType="boolean">
         <χ:atomic-value type="boolean">false</χ:atomic-value>
      </χ:entry>
      <χ:entry key="sequence" keyType="string">
         <χ:node type="document" instance="d3" ref="/"/>
         <χ:node type="element" instance="d3" path="/&#34;&#34;:node1[1]" name="node1"/>
         <χ:node type="element" instance="d3" path="/&#34;&#34;:node2[1]" name="node2"/>
         <χ:atomic-value type="number">2</χ:atomic-value>
      </χ:entry>
      <χ:entry key="5" keyType="number">
         <χ:atomic-value type="string">foo</χ:atomic-value>
         <χ:atomic-value type="string">bar</χ:atomic-value>
      </χ:entry>
   </χ:map>
</χ:data-model>

Map with all the different types of nodes

The map defined in XSLT as:

        <xsl:variable name="nodes">
            <my-element xmlns:ns="http:example.com" ns:my-attribute="foo">
                <xsl:comment>A comment</xsl:comment>
                <xsl:processing-instruction name="A">processing instruction</xsl:processing-instruction>
                <ns:a-sub-element>bar</ns:a-sub-element>
                <![CDATA[Some text]]>
            </my-element>
        </xsl:variable>
        <xsl:variable name="json"
            select="
            map {
                'doc':=  $nodes, 
            	'elt':=  $nodes/my-element,
            	'att':=  $nodes/my-element/@* ,
            	'text':= $nodes/my-element/text() ,
            	'pi':=   $nodes/my-element/processing-instruction(),
            	'comment':= $nodes/my-element/comment(),
            	'ns':= $nodes/my-element/namespace::* 
            }"/>

gives the following χίμαιραλ serialization:

<?xml version="1.0" encoding="UTF-8"?>
<χ:data-model xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:χ="http://χίμαιραλ.com#">
   <χ:instance id="d3">
      <my-element xmlns:ns="http:example.com" ns:my-attribute="foo"><!--A comment--><?A processing instruction?><ns:a-sub-element>bar</ns:a-sub-element>
                Some text
            </my-element>
   </χ:instance>
   <χ:map>
      <χ:entry key="ns" keyType="string">
         <χ:node type="namespace"
                 instance="d3"
                 path="/&#34;&#34;:my-element[1]/namespace::ns"
                 name="ns">http:example.com</χ:node>
         <χ:node type="namespace"
                 instance="d3"
                 path="/&#34;&#34;:my-element[1]/namespace::xs"
                 name="xs">http://www.w3.org/2001/XMLSchema</χ:node>
         <χ:node type="namespace"
                 instance="d3"
                 path="/&#34;&#34;:my-element[1]/namespace::χ"
                 name="χ">http://χίμαιραλ.com#</χ:node>
         <χ:node type="namespace"
                 instance="d3"
                 path="/&#34;&#34;:my-element[1]/namespace::xml"
                 name="xml">http://www.w3.org/XML/1998/namespace</χ:node>
      </χ:entry>
      <χ:entry key="text" keyType="string">
         <χ:node type="text" instance="d3" path="/&#34;&#34;:my-element[1]/text()[1]">
                Some text
            </χ:node>
      </χ:entry>
      <χ:entry key="doc" keyType="string">
         <χ:node type="document" instance="d3" ref="/"/>
      </χ:entry>
      <χ:entry key="att" keyType="string">
         <χ:node xmlns:ns="http:example.com"
                 type="attribute"
                 instance="d3"
                 path="/&#34;&#34;:my-element[1]/@&#34;http:example.com&#34;:my-attribute"
                 name="ns:my-attribute">foo</χ:node>
      </χ:entry>
      <χ:entry key="comment" keyType="string">
         <χ:node type="comment" instance="d3" path="/&#34;&#34;:my-element[1]/comment()[1]">A comment</χ:node>
      </χ:entry>
      <χ:entry key="pi" keyType="string">
         <χ:node type="processing-instruction"
                 instance="d3"
                 path="/&#34;&#34;:my-element[1]/processing-instruction(&#34;A&#34;)[1]"
                 name="A">processing instruction</χ:node>
      </χ:entry>
      <χ:entry key="elt" keyType="string">
         <χ:node type="element"
                 instance="d3"
                 path="/&#34;&#34;:my-element[1]"
                 name="my-element"/>
      </χ:entry>
   </χ:map>
</χ:data-model>

Note that the node type, name and value are indicative.

Map with nodes from different instances

The map defined in XSLT as:

        <xsl:variable name="json"
            select="map{
                'elt1'       := $nodes/my-element,
                'att'        := $nodes/my-element/@*,
                'elt2'       := $node/node1,
            }"/>

gives the following χίμαιραλ serialization:

<?xml version="1.0" encoding="UTF-8"?>
<χ:data-model xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:χ="http://χίμαιραλ.com#">
   <χ:instance id="d3">
      <node1>
         <foo/>
         <bar/>
      </node1>
      <node2/>
   </χ:instance>
   <χ:instance id="d4">
      <my-element xmlns:ns="http:example.com" ns:my-attribute="foo"><!--A comment--><?A processing instruction?><ns:a-sub-element>bar</ns:a-sub-element>
                Some text
            </my-element>
   </χ:instance>
   <χ:map>
      <χ:entry key="att" keyType="string">
         <χ:node xmlns:ns="http:example.com"
                 type="attribute"
                 instance="d4"
                 path="/&#34;&#34;:my-element[1]/@&#34;http:example.com&#34;:my-attribute"
                 name="ns:my-attribute">foo</χ:node>
      </χ:entry>
      <χ:entry key="elt1" keyType="string">
         <χ:node type="element"
                 instance="d4"
                 path="/&#34;&#34;:my-element[1]"
                 name="my-element"/>
      </χ:entry>
      <χ:entry key="elt2" keyType="string">
         <χ:node type="element" instance="d3" path="/&#34;&#34;:node1[1]" name="node1"/>
      </χ:entry>
   </χ:map>
</χ:data-model>

The http://χίμαιραλ.com# XML namespace

The preferred prefix for this namespace is the greek letter "χ".The namespace is composed of the following elements:

χ:data-model

An XDM 3.0 data model

Attributes

None

Content

χ:instance*, χ:map*

χ:instance

An XML instance

Attributes

  • id (mandatory): the instance id

Content

Any element from any other namespace.

χ:map

An XDM 3.0 map.

Attributes

None

Content

χ:entry *

χ:entry

An XDM 3.0 map entry.

Attributes

  • key (mandatory for map items): the value of the item key.
  • keyType (mandatory for map items): the type of the item key.
  • valueType (mandatory for atomic values): the type of the item value.

Content

(χ:map | χ:node | χ:atomic-value) *

One of these elements are mandatory when the valueType attribute is omitted.

χ:atomic-value

An XDM atomic value

Attributes

  • type: the type of the atomic value

Content

The value

χ:node

An XDM nodeset

Attributes

  • instance: the id of the instance holding the node
  • path: an XPath expression selecting the node in its instance
  • type (indicative): node type
  • name (when applicable, indicative): name of the node

Content

Depending on the node type: its value (indicative).

Changelog

This version (0.3) takes a new approach to represent nodes in map entries using XPath expressions rather than id/irdefs.

Main changes:

A detailed changelog is available at http://χίμαιραλ.com/trac/log/spec/index.html as a web page and as a RSS feed.

Legal Statement

Copyright (c) 2012 Eric van der Vlist

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ``Software''), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

  1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  2. The name of the authors when specified in the source files shall be kept unmodified.

THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ERIC VAN DER VLIST BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.