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

This Version: V 0.2 (TBD)

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

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.

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"?>
<χ:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:χ="http://χίμαιραλ.com#">
   <χ: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>

Map with two references to the same node

The map defined in XSLT as:

        <xsl:variable name="node">
            <node>
                <foo/>
                <bar/>
            </node>
        </xsl:variable>
        <xsl:variable name="json" select="map:new(
               (map:entry(5, 'foo'), 
               map:entry('bar', $node), 
               map:entry('bat', $node)))"/>

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

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

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"?>
<χ:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:χ="http://χίμαιραλ.com#">
   <χ: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>

Map with two instances of the same node, atomic values and other types of keys

The map defined in XSLT as:

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

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

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

Map with 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:new((
            map:entry('doc',  $nodes), 
            map:entry('elt',  $nodes/my-element),
            map:entry('att',  $nodes/my-element/@* ),
            map:entry('text', $nodes/my-element/text() ),
            map:entry('pi',   $nodes/my-element/processing-instruction() ),
            map:entry('comment', $nodes/my-element/comment() ),
            map:entry('ns', $nodes/my-element/namespace::* )
            ))"/>

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

<?xml version="1.0" encoding="UTF-8"?>
<χ:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:χ="http://χίμαιραλ.com#">
   <χ:entry key="ns" keyType="string">
      <χ:node type="namespace" name="ns">http:example.com</χ:node>
      <χ:node type="namespace" name="xs">http://www.w3.org/2001/XMLSchema</χ:node>
      <χ:node type="namespace" name="χ">http://χίμαιραλ.com#</χ:node>
      <χ:node type="namespace" name="xml">http://www.w3.org/XML/1998/namespace</χ:node>
   </χ:entry>
   <χ:entry key="text" keyType="string">
      <χ:node type="attribute">
                Some text
            </χ:node>
   </χ:entry>
   <χ:entry key="doc" keyType="string">
      <χ:node type="document">
         <my-element xmlns:ns="http:example.com" χ:id="d3e1" ns:my-attribute="foo"><!--A comment--><?A processing instruction?><ns:a-sub-element>bar</ns:a-sub-element>
                Some text
            </my-element>
      </χ:node>
   </χ:entry>
   <χ:entry key="att" keyType="string">
      <χ:node xmlns:ns="http:example.com" type="attribute" name="ns:my-attribute">foo</χ:node>
   </χ:entry>
   <χ:entry key="comment" keyType="string">
      <χ:node type="comment">A comment</χ:node>
   </χ:entry>
   <χ:entry key="pi" keyType="string">
      <χ:node type="processing-instruction" name="A">processing instruction</χ:node>
   </χ:entry>
   <χ:entry key="elt" keyType="string">
      <χ:node χ:idref="d3e1" type="element" name="my-element"/>
   </χ:entry>
</χ:map>

This last example is a good illustration of the issues we have when we want to mix items such as maps that have no identity nor context and nodes. To some extent it is possible to use id/idref to avoid to duplicate nodes (like we've done here with the element with χ:id="d3e1") but when we need the same feature for non element nodes that becomes much tickier since these nodes can't carry attributes.

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

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

χ: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

  • χ:id: an identifier for the node
  • χ:idref: a reference to a node identifier

These attributes are mutually exclusive.

  • type (mandatory): node type
  • name (when applicable): name of the node

Content

Depending on the node type: a value or a sequence of nodes.

Changelog

This version (0.2) tries to bring the serialization closer to the terms and concepts as they have been defined in the W3C XPath specifications.

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.