Changes

Jump to navigation Jump to search
739 bytes added ,  06:47, 29 November 2019
no edit summary
This page is part of the [[XQuery|XQuery Portal]].
Serialization parameters define how XQuery items and XML nodes are textually output, i.e., ''serialized''. (For input, see [[Parsers]].)
They have been formalized in the [http://www.w3.org/TR/xslt-xquery-serialization-31 W3C XQuery Serialization 3.1] document.
In BaseX, they can be specified by…
Serialization parameters define how XQuery items and XML nodes will be ''serialized'' (i.e., returned to the client or an API, usually in textual form). The official parameters are defined in the [http://www.w3.org/TR/xslt-xquery-serialization-31 W3C XQuery Serialization 3.1] document. In BaseX, they can be specified by: * including them in the [[XQuery_3.0#Serialization|prolog of the XQuery expression]],;
* specifying them in the XQuery functions [[File_Module#file:write|file:write()]] or [[XQuery_3.0#Functions|fn:serialize()]]. The serialization parameters are specified as
** children of an {{Code|<output:serialization-parameters/>}} element, as defined for the [http://www.w3.org/TR/xpath-functions-30/#func-serialize fn:serialize()] function, or as
** map, which contains all key/value pairs: <code>map { "method": "xml", "cdata-section-elements": "div", ... }</code>,;* using the {{Code|-s}} flag of the BaseX [[Command-Line Options#BaseX Standalone|command-line]] clients,;* setting the [[Options#SERIALIZER{{Option|SERIALIZER]] }} option before running a query,;* setting the [[Options#EXPORTER{{Option|EXPORTER]] }} option before exporting a database, ; or
* setting them as [[REST#Parameters|REST]] query parameters.
 
Due to the wide range of ways how parameters can be supplied, we deliberately ignored one rule of the specification, which requires non-official features to be defined in a non-null namespace URI. In the following, we will indicate which features are specific to our implementation.
=Parameters=
The following table gives a brief summary of all serialization parameters recognized are supported by BaseX. For (further details, please refer to can be looked up in the official specification.):
{| class="wikitable sortable" width="100%"
|- valign="top"
| {{Code|method}}
| Specifies the serialization method. {{Code|xml}}, {{Code|xhtml}}, {{Code|html}}, {{Code|text}}, {{Code|json}}, and {{Code|adaptive}} are adopted from part of the official specification. The methods For more details on {{Code|basex}}, {{Code|csv}} and {{Code|csvjson}} are specific to BaseX (, see [[XQuery Extensions#Serialization|XQuery Extensions]]).
| {{Code|xml}}, {{Code|xhtml}}, {{Code|html}}, {{Code|text}}, {{Code|json}}, {{Code|adaptive}}, {{Code|csv}}, {{Code|basex}}
| {{Code|basex}}
| {{Code|item-separator}}
| Determines a string to be used as item separator. If a separator is specified, the default separation of atomic values with single whitespaces will be skipped.
| ''arbitrary strings'', {{Code|\n}}, {{Code|\r\n}}, {{Code|\r}}
| ''empty''
|- valign="top"
| Inserts a {{Code|meta}} content-type element into the head element if the result is output as HTML<br />Example: <code>&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;&lt;/head&gt;</code>. The head element must already exist or nothing will be added. Any existing {{Code|meta}} content-type elements will be removed.
| {{Code|yes}}, {{Code|no}}
| {{Code|noyes}}
|}
The {{Code|csv}} and {{Code|json}} parameters are supplied with a list of options. Option names and values are combined with <code>=</code>, several options are separated by <code>,</code>:
'''Query''':
<pre class="brush:xquery">
(: The output namespace declaration is optional, because it is statically declared in BaseX) :)
</record>
</csv>
</pre>
 
If {{Code|fn:serialize}} is called, output-specific parameters can be supplied via nested options:
 
<pre class="brush:xquery">
serialize(
<csv>
<record>
<Name>John</Name>
<City>Newton</City>
</record>
<record>
<Name>Jack</Name>
<City>Oldtown</City>
</record>
</csv>,
map {
'method': 'csv',
'csv': map { 'header': 'yes', 'separator': ';' }
}
)
</pre>
Character maps allow a specific character in the instance of the data model to be replaced with a specified string of characters during serialization. The string that is substituted is output "as is," and the serializer performs no checks that the resulting document is well-formed. This may only occur in documents parsed with {{Code|parameter-document}}. If a character is mapped, then it is not subjected to XML or HTML escaping. For details refer to section [https://www.w3.org/TR/2015/CR-xslt-xquery-serialization-31-20151217/#character-maps 11 Character maps] in the [http://www.w3.org/TR/xslt-xquery-serialization-31 W3C XQuery Serialization 3.1] document
This example maps the Unicode U+00A0 NO-BREAK SPACE as &amp;#160; instead of (without the entity &amp;nbsp;.serialization parameter, the Unicode character would be output):
'''Example query''':
=Changelog=
 
;Version 9.2
 
* Updated: New default value for {{Code|include-content-type}} is {{Code|yes}}.
;Version 8.4
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu