Changes

Jump to navigation Jump to search
1,034 bytes added ,  18:39, 1 December 2023
m
Text replacement - "syntaxhighlight" to "pre"
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…
* including them in the [[XQuery_3.0#Serialization|prolog of the parameters define how XQuery expression]]items and XML nodes will be ''serialized'' (i.e.,* specifying them in returned to the XQuery functions [[File_Module#file:write|file:write()]] client or [[XQuery_3.0#Functions|fn:serialize(an API, usually in textual form)]]. The serialization official parameters are specified as** children of an {{Code|&lt;output:serialization-parameters/&gt;}} element, as defined for in the [httphttps://www.w3.org/TR/xpathxslt-functionsxquery-30/#funcserialization-serialize fn:serialize()31 W3C XQuery Serialization 3.1] function, or as** map, which contains all key/value pairs: <code>map { "method": "xml", "cdata-section-elements": "div", ..document. }</code>,* using the {{Code|-s}} flag of the BaseX [[Command-Line Options#In BaseX Standalone|command-line]] clients,* setting the [[Options#SERIALIZER|SERIALIZER]] option before running a query,* setting the [[Options#EXPORTER|EXPORTER]] option before exporting a database, or* setting them as [[REST#Parameters|REST]] query parameters.they can be:
* included in the [[XQuery_3.0#Serialization|prolog of the XQuery expression]];* specified in XQuery functions ({{Function|File|file:write}}, {{Function|Database|db:export}}, [https://www.w3.org/TR/xpath-functions-31/#func-serialize fn:serialize()]);* specified in [[REST#Parameters|REST query parameters]];* specified in [[RESTXQ#Output|RESTXQ output annotations]];* set via the {{Option|SERIALIZER}} option before running a query;* set via the {{Option|EXPORTER}} option before exporting a database; or* supplied with the {{Code|-s}} flag of the BaseX [[Command-Line Options#BaseX Standalone|command-line]] clients. The namespace for serialization parameters is statically bound to the {{Code|output}} prefix. This means that it need not (but may) be declared in the query prolog: <pre lang='xquery'>declare namespace output = 'http://www.w3.org/2010/xslt-xquery-serialization';declare option output:method 'text';<xml>Hi there</xml></pre> 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. =Standard Parameters=
The following serialization parameters are supported by BaseX (further details can be looked up in the official specification):
|- 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 stringsstring''| ''empty''
|- valign="top"
| {{Code|encoding}}
| Encoding to be used for outputting the data.
| ''[httphttps://docs.oracle.com/javase/78/docs/technotes/guides/intl/encoding.doc.html all encodings supported by Java]''
| {{Code|UTF-8}}
|- valign="top"
| {{Code|indent}}
| Adjusts Adds leading whitespaces to make the output better more readable.
| {{Code|yes}}, {{Code|no}}
| {{Code|yesno}}
|- valign="top"
| {{Code|cdata-section-elements}}
| List of elements to be output as CDATA, separated by whitespaces.<br />Example: {{Code|&lt;text&gt;&lt;![CDATA[ &lt;&gt; ]]&gt;&lt;/text&gt;}}| ''string''
|
|- valign="top"
| {{Code|omit-xml-declaration}}
| Omits the XML declaration, which is serialized before the actual query result<br />Example: <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code>
| {{Code|yes}}, {{Code|no}}
| {{Code|yes}}
|- valign="top"
| {{Code|standalone}}
| Prints or omits the "{{Code|standalone" }} attribute in the XML declaration.
| {{Code|yes}}, {{Code|no}}, {{Code|omit}}
| {{Code|omit}}
|- valign="top"
| {{Code|doctype-system}}
| Introduces the output with a document type declaration and the given system identifier.<br />Example: {{Code|&lt;!DOCTYPE x SYSTEM "entities.dtd"&gt;}}|''string''
|
|- valign="top"
| {{Code|doctype-public}}
| If {{Code|doctype-system}} is specified, adds a public identifier.<br />Example: {{Code|&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "<nowiki>http://www.w3.org/TR/html4/strict.dtd</nowiki>"&gt;}}| ''string''
|
|- valign="top"
| {{Code|media-type}}
| Specifies the media type.
| ''string''
| {{Code|application/xml}}
|- valign="top"
| {{Code|parameter-document}}
| Parses the value as XML document with additional serialization parameters (see the [http://www.w3.org/TR/xslt-xquery-serialization-31/#serparams-in-xdm-instance Serialization Specification] for more details).
|
|
|- valign="top"
| {{Code|use-character-maps}}
| Defines character mappings. May only occur in documents parsed with {{Code|parameter-document}}If mappings are supplied as a single string, keys and values are separated by the equal sign, and multiple pairs are separated by commas. Separators that are to be defined as keys or values can be encoded as entities.<br/>Example: <code>A=alpha,B=beta</code>| ''string''
|
|- valign="top"
|- valign="top"
| {{Code|escape-uri-attributes}}
| Escapes URI information in certain HTML attributes<br />Example: <code>&lt;a&nbsp;href="%C3%A4%C3%B6%C3%BC"&gt;äöü&lt;a&gt;</code>
| {{Code|yes}}, {{Code|no}}
| {{Code|no}}
|- valign="top"
| {{Code|include-content-type}}
| 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}}|} =Query Prolog Parameters= The following parameters can only be specified in the query prolog (see [https://www.w3.org/TR/xquery-31/#id-serialization XQuery: Specification] for more details and examples): {| class="wikitable sortable" width="100%"|- valign="top"! width="140" | Parameter! Description! Allowed! Default|- valign="top"| {{Code|parameter-document}}| Parses the value as an XML document with additional serialization parameters.| ''string''|
|}
 
=Custom Parameters=
BaseX provides some additional serialization parameters:
| ''positive number''
| {{Code|2}}
|- valign="top"
| {{Code|indent-attributes}}
| {{Announce|Version 11:}} Indent attributes after the element name, one below the other.
| {{Code|yes}}, {{Code|no}}
| {{Code|false}}
|- valign="top"
| {{Code|newline}}
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>:
<pre classlang="brush:'xquery"'>(: The output namespace declaration is optional, because it is statically declared in BaseX) :)declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "csv";
declare option output:csv "header=yes, separator=semicolon";
If {{Code|fn:serialize}} is called, output-specific parameters can be supplied via nested options:
<pre classlang="brush:'xquery"'>
serialize(
<csv>
'''Result''':
<pre classlang="brush:xml">
Name;City
John;Newton
=Character mappings=
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 “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 [httphttps://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; (without the serialization parameter, the Unicode character would be output):
'''Example query''':
<pre classlang="brush:'xquery"'>
declare option output:parameter-document "map.xml";
<x>&amp;#xA0;</x>
'''Example parameter-document''':
<pre classlang="brush:xml">
<serialization-parameters
xmlns="http://www.w3.org/2010/xslt-xquery-serialization">
=Changelog=
 
;Version 11.0
* Added: Serialization parameter {{Code|indent-attributes}}.
 
;Version 10.0
* Updated: {{Code|indent}}: Default changed from {{Code|yes}} to {{Code|no}}.
 
;Version 9.2
* Updated: New default value for {{Code|include-content-type}} is {{Code|yes}}.
;Version 8.4
 
* Added: Serialization parameter {{Code|binary}}.
* Updated: New serialization method <code>basex</code>. By default, items of binary type are now output in their native byte representation. The method <code>raw</code> was removed.
;Version 8.0
 
* Added: Support for {{Code|use-character-maps}} and {{Code|parameter-document}}.
* Added: Serialization method {{Code|adaptive}}.
;Version 7.8.2
 
* Added: {{Code|limit}}: Stops serialization after the specified number of bytes has been serialized.
;Version 7.8
 
* Added: {{Code|csv}} and {{Code|json}} serialization parameters.
* Removed: {{Code|separator}} option (use {{Code|item-separator}} instead).
;Version 7.7.2
 
* Added: {{Code|csv}} serialization method.
* Added: temporary serialization methods {{Code|csv-header}}, {{Code|csv-separator}}, {{Code|json-unescape}}, {{Code|json-spec}}, {{Code|json-format}}.
;Version 7.5
 
* Added: official {{Code|item-separator}} and {{Code|html-version}} parameter.
* Updated: <code>method=html5</code> removed; serializers updated with the [httphttps://www.w3.org/TR/2013/WD-xslt-xquery-serialization-30-20130108/ latest version of the specification], using <code>method=html</code> and <code>version=5.0</code>.
;Version 7.2
 
* Added: {{Code|separator}} parameter.
;Version 7.1
 
* Added: {{Code|newline}} parameter.
;Version 7.0
 
* Added: Serialization parameters added to [[REST API]]; JSON/JsonML/raw methods.
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu