Stephen M. McKamey, 2006-11-16

JsonML - Converting XML to JsonML

Intention of JsonML

Despite XHTML UI markup being the initial use case for JsonML, the intention is that any XML representation may be efficiently represented in JsonML. In this sense, authors may be able to work in a format which is more familiar while still leveraging the advantages of a JSON-savvy framework. In order to demonstrate its usage, an open-source transformation to produce JsonML from XML and open-source JavaScript to produce W3C DOM elements from JsonML are both available.

XML Examples

To best demonstrate the ease of this conversion from XML, here are some examples of XHTML in with an XML-to-JsonML XSLT applied to them. View source to see the input before the web browser applies the transformation:

XML to JsonML Mapping

Element Nodes

Elements are supported directly in the grammar as a first class concept.

Attribute Nodes

Attributes are supported directly in the grammar as a first class concept.

Text Nodes

Text nodes are supported directly in the grammar as a first class concept.

Comment Nodes

JSON specification removed support for comments a while back for better or worse (note the lengthy "Comments" discussion). As such, JsonML inherits this treatment of comments. The reference XML-to-JsonML XSLT has a template for producing inline JavaScript comments from the XML comments; however, this template is commented out by default.

Namespace Nodes

Namespace nodes themselves do not directly appear in the output. Namespace prefixes may be included right in the tag-name string (e.g. "myns:my-tag"). Resolving these to their URI follows the same syntax as in XML via an "xmlns" or "xmlns:prefix" attribute where the URI is specified as the value.

The reference XML-to-JsonML XSLT explicitly removes the namespace prefix from any element or attribute within the XHTML namespace. The reason being that when used in combination with the reference JsonML UI Builder, the DOM is expecting namespace free HTML elements.

The inclusion of namespace support in JsonML is to enable a wider range of uses beyond that of HTML markup.

Processing Instructions

Processing instruction nodes are inherently ignored in JsonML. There does not seem to be a useful analogy which is consistent with the intent of JsonML. The reference JsonML UI Builder does include support for executing inline JavaScript.