A RESTful browser for eXist Function Modules


http://www.json.org
Transform XML fragments into JSON. The target of this module is to create a straight-forward Javasript representation of data-centric XML. It does not try to handle mixed content nodes (with a mix of elements and text).

Special rules

The root element will be absorbed, i.e. <root>text</root> becomes "text".

Child elements with the same name are added to an array.

If an element has attribute and text content, the text content becomes a property, e.g. '#text': 'my text'.

In mixed content nodes, text nodes will be dropped.

An empty element becomes 'null', i.e. <e/> becomes {"e": null}.

An element with a single text child becomes a property with the value of the text child, i.e. <e>text</e> becomes {"e": "text"}

If the attribute json:literal="true" is present on an element, then its text value is considered literal and not quoted as a string. Useful for boolean and numberic values!


json:element-helper($attribs as attribute()*, $children as node()*)
Helper function: output element content for elements with more than one child node or attribute. Special cases:

json:contents-to-json($node as node())
Helper function: output the contents of a node or attribute. Special cases:

json:node-to-json($node as node()+)
Helper function: convert a node into JSON.

json:xml-to-json($node as node())
Main entry point of the module. Convert a single node into JSON. The root element will be absorbed.
Return to list of all modules