Hi,
I'm playing with the new XQuery 3.1 functions amongst which the JSON-serilization.
I would expect all three snippets below to result in the same output but all three give a different result.
Snippet 1:
=======
declare option output:method 'json';
serialize( <a>test</a>
)
Snippet 2:
=======
serialize( <a>test</a>
, map{ 'method' : 'json'}
)
Snippet 3:
=======
declare option output:method 'json';
serialize( <a>test</a>
, map{ 'method' : 'json'}
)
If I do the same with XML-serilization than all three results are the same.
Are my expectations correct in this?
- Rob
--- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com
Hi Rob
the behavior is correct:
declare option output:method 'json'; serialize( <a>test</a> )
The result is:
"<a>test</a>"
…as specified in [1].
serialize( <a>test</a> , map{ 'method' : 'json'} )
The result is:
"<a>test</a>"
The node will first be serialized to a string, and the query result (i.e., this string) will be serialized according to the XML serialization rules. You can switch to plain text serialization as follows:
declare option output:method 'text'; serialize( <a>test</a>, map{ 'method' : 'json'} )
declare option output:method 'json'; serialize( <a>test</a> , map{ 'method' : 'json'} )
The result is:
""<a>test</a>""
The node will first be serialized to a string, and the query result (i.e., this string) will be serialized according to the JSON serialization rules. In a JSON string, quotes will be backslashed.
Cheers, Christian
[1] http://www.w3.org/TR/xslt-xquery-serialization-31/#JSON_JSON-NODE-OUTPUT-MET...
Hi Christian,
Thanx for the quick response. I get it.
In my case I want the result of the first snippet but then in a xquery-module. I can't use the: "declare option ....." in a module. Can you give me a suggestion how to realize this?
Thanx in advance,
Rob
-----Oorspronkelijk bericht----- Van: Christian Grün [mailto:christian.gruen@gmail.com] Verzonden: donderdag 27 november 2014 11:53 Aan: Rob Stapper CC: BaseX Onderwerp: Re: [basex-talk] unexpected behaviour
Hi Rob
the behavior is correct:
declare option output:method 'json'; serialize( <a>test</a> )
The result is:
"<a>test</a>"
…as specified in [1].
serialize( <a>test</a> , map{ 'method' : 'json'} )
The result is:
"<a>test</a>"
The node will first be serialized to a string, and the query result (i.e., this string) will be serialized according to the XML serialization rules. You can switch to plain text serialization as follows:
declare option output:method 'text'; serialize( <a>test</a>, map{ 'method' : 'json'} )
declare option output:method 'json'; serialize( <a>test</a> , map{ 'method' : 'json'} )
The result is:
""<a>test</a>""
The node will first be serialized to a string, and the query result (i.e., this string) will be serialized according to the JSON serialization rules. In a JSON string, quotes will be backslashed.
Cheers, Christian
[1] http://www.w3.org/TR/xslt-xquery-serialization-31/#JSON_JSON-NODE-OUTPUT-MET...
--- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com
basex-talk@mailman.uni-konstanz.de