Difference between revisions of "Serialization"

From BaseX Documentation
Jump to navigation Jump to search
Line 24: Line 24:
 
| <code>method</code>
 
| <code>method</code>
 
| Specifies the serialization method. If <code>json</code> is specified, the XML document must conform to the BaseX [[JSON Functions|JSON syntax]].
 
| Specifies the serialization method. If <code>json</code> is specified, the XML document must conform to the BaseX [[JSON Functions|JSON syntax]].
| <code>xml,xhtml,html, text,json</code>
+
| <code>xml, xhtml, html, text, json</code>
 
| <code>xml</code>
 
| <code>xml</code>
 
| <code>method=xml</code>
 
| <code>method=xml</code>
Line 30: Line 30:
 
| <code>version</code>
 
| <code>version</code>
 
| Specifies the XML version.
 
| Specifies the XML version.
| <code>1.0,1.1</code>
+
| <code>1.0, 1.1</code>
 
| <code>1.0</code>
 
| <code>1.0</code>
 
| <code>version=1.0</code>
 
| <code>version=1.0</code>
Line 42: Line 42:
 
| <code>indent</code>
 
| <code>indent</code>
 
| Adjusts whitespaces to make the output better readable.
 
| Adjusts whitespaces to make the output better readable.
| <code>yes,no</code>
+
| <code>yes, no</code>
 
| <code>yes</code>
 
| <code>yes</code>
 
| <code>indent=no</code>
 
| <code>indent=no</code>
Line 54: Line 54:
 
| <code>omit-xml-declaration</code>
 
| <code>omit-xml-declaration</code>
 
| 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>
 
| 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,no</code>
+
| <code>yes, no</code>
 
| <code>yes</code>
 
| <code>yes</code>
 
| <code>omit-xml-declaration=no</code>
 
| <code>omit-xml-declaration=no</code>
Line 60: Line 60:
 
| <code>standalone</code>
 
| <code>standalone</code>
 
| Prints or omits the "standalone" attribute in the XML declaration.
 
| Prints or omits the "standalone" attribute in the XML declaration.
| <code>yes,no,omit</code>
+
| <code>yes, no, omit</code>
 
| <code>omit</code>
 
| <code>omit</code>
 
| <code>standalone=yes</code>
 
| <code>standalone=yes</code>
Line 78: Line 78:
 
| <code>undeclare-prefixes</code>
 
| <code>undeclare-prefixes</code>
 
| Undeclares prefixes in XML 1.1.
 
| Undeclares prefixes in XML 1.1.
| <code>yes,no</code>
+
| <code>yes, no</code>
 
| <code>no</code>
 
| <code>no</code>
 
| <code>undeclare-prefixes=yes</code>
 
| <code>undeclare-prefixes=yes</code>
Line 84: Line 84:
 
| <code>normalization-form</code>
 
| <code>normalization-form</code>
 
| Specifies a normalization form. BaseX supports Form C (<code>NFC</code>).
 
| Specifies a normalization form. BaseX supports Form C (<code>NFC</code>).
| <code>NFC,none</code>
+
| <code>NFC, none</code>
 
| <code>NFC</code>
 
| <code>NFC</code>
 
| <code>normalization-form=none</code>
 
| <code>normalization-form=none</code>
Line 102: Line 102:
 
| <code>byte-order-mark</code>
 
| <code>byte-order-mark</code>
 
| Prints a byte-order-mark before starting serialization.
 
| Prints a byte-order-mark before starting serialization.
| <code>yes,no</code>
+
| <code>yes, no</code>
 
| <code>no</code>
 
| <code>no</code>
 
| <code>byte-order-mark=yes</code>
 
| <code>byte-order-mark=yes</code>
Line 108: Line 108:
 
| <code>escape-uri-attributes</code>
 
| <code>escape-uri-attributes</code>
 
| 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>
 
| 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,no</code>
+
| <code>yes, no</code>
 
| <code>no</code>
 
| <code>no</code>
 
| <code>escape-uri-attributes=yes, method=html</code>
 
| <code>escape-uri-attributes=yes, method=html</code>
Line 114: Line 114:
 
| <code>include-content-type</code>
 
| <code>include-content-type</code>
 
| Includes a <code>meta</code> content-type 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>
 
| Includes a <code>meta</code> content-type 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>
| <code>yes,no</code>
+
| <code>yes, no</code>
 
| <code>no</code>
 
| <code>no</code>
 
| <code>include-content-type=yes, method=html</code>
 
| <code>include-content-type=yes, method=html</code>
Line 131: Line 131:
 
| <code>format</code>
 
| <code>format</code>
 
| Turns output formatting on/off, including the conversion of special characters to entities. This flag can be turned off to simplify the handling of plain-text results.
 
| Turns output formatting on/off, including the conversion of special characters to entities. This flag can be turned off to simplify the handling of plain-text results.
| <code>yes,no</code>
+
| <code>yes, no</code>
 
| <code>yes</code>
 
| <code>yes</code>
 
| <code>format=no</code>
 
| <code>format=no</code>
Line 137: Line 137:
 
| <code>tabulator</code>
 
| <code>tabulator</code>
 
| Uses tab characters (<code>\t</code>) for indenting elements.
 
| Uses tab characters (<code>\t</code>) for indenting elements.
| <code>yes,no</code>
+
| <code>yes, no</code>
 
| <code>no</code>
 
| <code>no</code>
 
| <code>tabulator=yes</code>
 
| <code>tabulator=yes</code>

Revision as of 17:15, 14 August 2011

Serialization parameters define how XQuery items and XML nodes are textually output, i.e., serialized. They have been formalized in the W3C XQuery Serialization 3.0 document. In BaseX, they can be specified in several ways:

Parameters

The following table gives a brief summary of all serialization parameters recognized by BaseX. For details, please refer to official specification.

Parameter Description Allowed Default Examples
method Specifies the serialization method. If json is specified, the XML document must conform to the BaseX JSON syntax. xml, xhtml, html, text, json xml method=xml
version Specifies the XML version. 1.0, 1.1 1.0 version=1.0
encoding Encoding to be used for outputting the data. UTF-8 encoding=US-ASCII
indent Adjusts whitespaces to make the output better readable. yes, no yes indent=no
cdata-section-elements List of elements to be output as CDATA, separated by whitespaces.
Example: <text><![CDATA[ <> ]]></text>
cdata-section-elements=text
omit-xml-declaration Omits the XML declaration, which is serialized before the actual query result
Example: <?xml version="1.0" encoding="UTF-8"?>
yes, no yes omit-xml-declaration=no
standalone Prints or omits the "standalone" attribute in the XML declaration. yes, no, omit omit standalone=yes
doctype-system Introduces the output with a document type declaration and the given system identifier.
Example: <!DOCTYPE x SYSTEM "entities.dtd">
doctype-system=entities.dtd
doctype-public If doctype-system is specified, adds a public identifier.
Example: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
doctype-public=-//W3C//DTD HTML 4.01//EN,
doctype-system=http://www.w3.org/TR/html4/strict.dtd
undeclare-prefixes Undeclares prefixes in XML 1.1. yes, no no undeclare-prefixes=yes
normalization-form Specifies a normalization form. BaseX supports Form C (NFC). NFC, none NFC normalization-form=none
media-type Specifies the media type. application/xml media-type=text/plain
use-character-maps Defines character mappings (not supported).
byte-order-mark Prints a byte-order-mark before starting serialization. yes, no no byte-order-mark=yes
escape-uri-attributes Escapes URI information in certain HTML attributes
Example: <a href="%C3%A4%C3%B6%C3%BC">äöü<a>
yes, no no escape-uri-attributes=yes, method=html
include-content-type Includes a meta content-type element if the result is output as HTML
Example: <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
yes, no no include-content-type=yes, method=html

BaseX provides some additional, implementation-defined serialization parameters:

Parameter Description Allowed Default Examples
format Turns output formatting on/off, including the conversion of special characters to entities. This flag can be turned off to simplify the handling of plain-text results. yes, no yes format=no
tabulator Uses tab characters (\t) for indenting elements. yes, no no tabulator=yes
indents Specifies the number of characters to be indented. 2 indents=1, tabulator=yes
wrap-prefix,
wrap-uri
Specifies a prefix and/or URI for wrapping the query results. wrap-prefix=jax-rx, wrap-uri=http://jax-rx.sourceforge.net