Changes

Jump to navigation Jump to search
1,706 bytes added ,  01:51, 15 August 2011
no edit summary
=JSON=
[[JSON Functions#json:parse|json:parse]] and [[JSON Functions#json:serialize|json:serialize]] facilitate a lossless representation of conversion from JSON to XML and back. The transformation is based on the following rules:
# The resulting document has a <code><json/></code> root node.
# Names (keys) of objects are represented as elements:
|<b>[[XQuery Errors#BaseX Errors (BASX)|BASX0015]]</b> is raised if the specified input cannot be parsed as JsonML instance.
|}
 
==Examples==
 
'''Example 1: A basic example to convert an empty XML document'''
 
'''Query:'''
<pre class="brush:xquery">
json:serialize-ml(<xml/>)
</pre>
 
'''Result:'''
<pre class="brush:json">
["xml"]
</pre>
 
'''Example 2: Conversion of some simple objects and arrays'''
 
'''Query:'''
<pre class="brush:xquery">
json:serialize-ml(doc('input.xml'))
</pre>
 
'''input.xml:'''
<pre class="brush:xml">
'''input.xml:'''
<pre class="brush:xml">
<address id='1'>
<last_name>Smith</last_name>
<age>25</age>
<address>
<street>21 2nd Street</street>
<city>New York</city>
<code>10021</code>
</address>
<phone type='home'>212 555-1234</phone>
</address>
</pre>
 
'''Result:'''
<pre class="brush:json">
["flickr",
["title",
"Talk On Travel Pool"],
["link",
"http:\/\/www.flickr.com\/groups\/talkontravel\/pool\/"],
["description",
"Travel and vacation photos from around the world."],
["modified",
"2009-02-02T11:10:27Z"],
["generator",
"http:\/\/www.flickr.com\/"]]
</pre>
 
'''Example 3: Nested document with attributes'''
 
'''Query:'''
<pre class="brush:json">
json:serialize-ml(doc('input.xml'))
</pre>
 
'''input.xml:'''
<pre class="brush:xml">
<address id='1'>
<last_name>Smith</last_name>
<age>25</age>
<address>
<street>21 2nd Street</street>
<city>New York</city>
<code>10021</code>
</address>
<phone type='home'>212 555-1234</phone>
</address>
</pre>
 
'''Result:'''
<pre class="brush:json">
["address", {"id":"1"},
["last_name",
"Smith"],
["age",
"25"],
["address",
["street",
"21 2nd Street"],
["city",
"New York"],
["code",
"10021"]],
["phone", {"type":"home"},
"212 555-1234"]]
</pre>
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu