Changes

Jump to navigation Jump to search
100 bytes added ,  17:11, 18 February 2015
===Annotations===
The serialization can also be parameterized via <code>%output</code> annotations. The following function, when called, generates XHTML headers, and {{Code|text/html}} will be set as content type:
<pre class="brush:xquery">
declare %rest:path("") %output:mediamethod("xhtml") %output:omit-xml-declaration("no") %output:doctype-typepublic("text-//plainW3C//DTD XHTML 1.0 Transitional//EN") %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd") function page:html(){ <html xmlns="http://www.w3.org/1999/xhtml"> <body>done</body> </html>};</pre> The next example serializes XML nodes as JSON, using the [[JSON Module|JsonML]] format: <pre class="brush:xquery">declare %rest:path("version2cities") %output:method("json") %output:json("format=jsonml") function page:version2cities() { element cities { db:open('Still somewhat simple.factbook')//city/name }
};
</pre>
When using <code>raw</code>, binary data will be sent in its original byte representation, i. e., without further conversion.
 
By default, {{Code|application/xml}} is returned as content type. In the following example, XHTML headers will be generated, and {{Code|text/html}} will be set as content type:
 
<pre class="brush:xquery">
declare
%rest:path("")
%output:method("xhtml")
%output:omit-xml-declaration("no")
%output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
%output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
function page:start()
{
<html xmlns="http://www.w3.org/1999/xhtml">
<body>done</body>
</html>
};
</pre>
=Error Handling=
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu