Difference between revisions of "Serialization"

From BaseX Documentation
Jump to navigation Jump to search
Line 18: Line 18:
 
|- valign="top"
 
|- valign="top"
 
! width="140" | Parameter
 
! width="140" | Parameter
! width="45%" | Description
+
! width="60%" | Description
 
! Allowed
 
! Allowed
 
! Default
 
! Default
! Examples
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|method}}
 
| {{Code|method}}
Line 32: Line 31:
 
| {{Code|xml}}, {{Code|xhtml}}, {{Code|html}}, {{Code|text}}, {{Code|json}}, {{Code|csv}}, {{Code|raw}}
 
| {{Code|xml}}, {{Code|xhtml}}, {{Code|html}}, {{Code|text}}, {{Code|json}}, {{Code|csv}}, {{Code|raw}}
 
| {{Code|xml}}
 
| {{Code|xml}}
| <code>method=xml</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|version}}
 
| {{Code|version}}
Line 38: Line 36:
 
| {{Code|xml/xhtml}}: {{Code|1.0}}, {{Code|1.1}}<br/>{{Code|html}}: {{Code|4.0}}, {{Code|4.01}}, {{Code|5.0}}<br/>
 
| {{Code|xml/xhtml}}: {{Code|1.0}}, {{Code|1.1}}<br/>{{Code|html}}: {{Code|4.0}}, {{Code|4.01}}, {{Code|5.0}}<br/>
 
| {{Code|1.0}}
 
| {{Code|1.0}}
| <code>version=1.0</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|html-version}}
 
| {{Code|html-version}}
Line 44: Line 41:
 
| {{Code|4.0}}, {{Code|4.01}}, {{Code|5.0}}
 
| {{Code|4.0}}, {{Code|4.01}}, {{Code|5.0}}
 
| {{Code|4.0}}
 
| {{Code|4.0}}
| <code>html-version=5.0</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|item-separator}}
 
| {{Code|item-separator}}
Line 50: Line 46:
 
| ''arbitrary strings'', {{Code|\n}}, {{Code|\r\n}}, {{Code|\r}}
 
| ''arbitrary strings'', {{Code|\n}}, {{Code|\r\n}}, {{Code|\r}}
 
| ''empty''
 
| ''empty''
| <code>item-separator=&#a;</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|encoding}}
 
| {{Code|encoding}}
Line 56: Line 51:
 
| ''[http://docs.oracle.com/javase/7/docs/technotes/guides/intl/encoding.doc.html all encodings supported by Java]''
 
| ''[http://docs.oracle.com/javase/7/docs/technotes/guides/intl/encoding.doc.html all encodings supported by Java]''
 
| {{Code|UTF-8}}
 
| {{Code|UTF-8}}
| <code>encoding=US-ASCII</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|indent}}
 
| {{Code|indent}}
Line 62: Line 56:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}
 
| {{Code|yes}}
| <code>indent=no</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|cdata-section-elements}}
 
| {{Code|cdata-section-elements}}
Line 68: Line 61:
 
|  
 
|  
 
|  
 
|  
| <code>cdata-section-elements=text</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|omit-xml-declaration}}
 
| {{Code|omit-xml-declaration}}
Line 74: Line 66:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}
 
| {{Code|yes}}
| <code>omit-xml-declaration=no</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|standalone}}
 
| {{Code|standalone}}
Line 80: Line 71:
 
| {{Code|yes}}, {{Code|no}}, {{Code|omit}}
 
| {{Code|yes}}, {{Code|no}}, {{Code|omit}}
 
| {{Code|omit}}
 
| {{Code|omit}}
| <code>standalone=yes</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|doctype-system}}
 
| {{Code|doctype-system}}
Line 86: Line 76:
 
|
 
|
 
|
 
|
| <code>doctype-system=entities.dtd</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|doctype-public}}
 
| {{Code|doctype-public}}
Line 92: Line 81:
 
|  
 
|  
 
|
 
|
| <code>doctype-public=-//W3C//DTD HTML 4.01//EN,<br />doctype-system=http://www.w3.org/TR/html4/strict.dtd</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|undeclare-prefixes}}
 
| {{Code|undeclare-prefixes}}
Line 98: Line 86:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|no}}
 
| {{Code|no}}
| <code>undeclare-prefixes=yes</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|normalization-form}}
 
| {{Code|normalization-form}}
Line 104: Line 91:
 
| {{Code|NFC}}, {{Code|none}}
 
| {{Code|NFC}}, {{Code|none}}
 
| {{Code|NFC}}
 
| {{Code|NFC}}
| <code>normalization-form=none</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|media-type}}
 
| {{Code|media-type}}
Line 110: Line 96:
 
|  
 
|  
 
| {{Code|application/xml}}
 
| {{Code|application/xml}}
| <code>media-type=text/plain</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|use-character-maps}}
 
| {{Code|use-character-maps}}
Line 116: Line 101:
 
|  
 
|  
 
|  
 
|  
|
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|byte-order-mark}}
 
| {{Code|byte-order-mark}}
Line 122: Line 106:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|no}}
 
| {{Code|no}}
| <code>byte-order-mark=yes</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|escape-uri-attributes}}
 
| {{Code|escape-uri-attributes}}
Line 128: Line 111:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|no}}
 
| {{Code|no}}
| <code>escape-uri-attributes=yes, method=html</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|include-content-type}}
 
| {{Code|include-content-type}}
Line 134: Line 116:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|no}}
 
| {{Code|no}}
| <code>include-content-type=yes, method=html</code>
 
 
|}
 
|}
  
Line 142: Line 123:
 
|- valign="top"
 
|- valign="top"
 
! width="140" | Parameter
 
! width="140" | Parameter
! width="45%" | Description
+
! width="60%" | Description
 
! Allowed
 
! Allowed
 
! Default
 
! Default
! Examples
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|csv-header}}
 
| {{Code|csv-header}}
Line 151: Line 131:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|no}}
 
| {{Code|no}}
| <code>csv-header=yes</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|csv-separator}}
 
| {{Code|csv-separator}}
Line 157: Line 136:
 
| ''single character''
 
| ''single character''
 
| {{Code|,}}
 
| {{Code|,}}
| <code>csv-separator=&amp;#9;</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|json-spec}}
 
| {{Code|json-spec}}
Line 163: Line 141:
 
| {{Code|RFC4627}}, {{Code|ECMA-262}}, {{Code|liberal}}
 
| {{Code|RFC4627}}, {{Code|ECMA-262}}, {{Code|liberal}}
 
| {{Code|RFC4627}}
 
| {{Code|RFC4627}}
| <code>json-spec=liberal</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|json-unescape}}
 
| {{Code|json-unescape}}
Line 169: Line 146:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}
 
| {{Code|yes}}
| <code>json-unescape=no</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|json-format}}
 
| {{Code|json-format}}
Line 175: Line 151:
 
| {{Code|json}}, {{Code|jsonml}}
 
| {{Code|json}}, {{Code|jsonml}}
 
| {{Code|json}}
 
| {{Code|json}}
| <code>json-format=jsonml</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|format}}
 
| {{Code|format}}
Line 181: Line 156:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}
 
| {{Code|yes}}
| <code>format=no</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|tabulator}}
 
| {{Code|tabulator}}
Line 187: Line 161:
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|yes}}, {{Code|no}}
 
| {{Code|no}}
 
| {{Code|no}}
| <code>tabulator=yes</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|indents}}
 
| {{Code|indents}}
Line 193: Line 166:
 
| ''positive number''
 
| ''positive number''
 
| {{Code|2}}
 
| {{Code|2}}
| <code>indents=1, tabulator=yes</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|wrap-prefix}},<br />{{Code|wrap-uri}}
 
| {{Code|wrap-prefix}},<br />{{Code|wrap-uri}}
Line 199: Line 171:
 
|  
 
|  
 
|  
 
|  
| <code>wrap-prefix=rest, wrap-uri=http://basex.org/rest</code>
 
 
|- valign="top"
 
|- valign="top"
 
| {{Code|newline}}
 
| {{Code|newline}}
Line 205: Line 176:
 
| {{Code|\n}}, {{Code|\r\n}}, {{Code|\r}}
 
| {{Code|\n}}, {{Code|\r\n}}, {{Code|\r}}
 
| ''system dependent''
 
| ''system dependent''
| <code>newline=\r\n</code>
 
 
|}
 
|}
  

Revision as of 22:41, 17 October 2013

This page is part of the 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 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
method Specifies the serialization method:
  • xml, xhtml, html, and text are adopted from the official specification.
  • json is specific to BaseX and can be used to output XML nodes as JSON objects (see the JSON Module for more details).
  • Version 7.7.2: csv is BaseX-specific and can be used to output XML nodes as CSV data (see the CSV Module for more details).
  • raw is BaseX-specific, too: Binary data types are output in their raw form, i.e., without modifications. For all other types, the items’ string values are returned. No indentation takes place, and and no characters are encoded via entities.
  • Version 7.7.2: jsonml is deprecated.
xml, xhtml, html, text, json, csv, raw xml
version Specifies the version of the serialization method. xml/xhtml: 1.0, 1.1
html: 4.0, 4.01, 5.0
1.0
html-version Specifies the version of the HTML serialization method. 4.0, 4.01, 5.0 4.0
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, \n, \r\n, \r empty
encoding Encoding to be used for outputting the data. all encodings supported by Java UTF-8
indent Adjusts whitespaces to make the output better readable. yes, no yes
cdata-section-elements List of elements to be output as CDATA, separated by whitespaces.
Example: <text><![CDATA[ <> ]]></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
standalone Prints or omits the "standalone" attribute in the XML declaration. yes, no, omit omit
doctype-system Introduces the output with a document type declaration and the given system identifier.
Example: <!DOCTYPE x 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">
undeclare-prefixes Undeclares prefixes in XML 1.1. yes, no no
normalization-form Specifies a normalization form. BaseX supports Form C (NFC). NFC, none NFC
media-type Specifies the media type. application/xml
use-character-maps Defines character mappings (not supported).
byte-order-mark Prints a byte-order-mark before starting serialization. yes, no no
escape-uri-attributes Escapes URI information in certain HTML attributes
Example: <a href="%C3%A4%C3%B6%C3%BC">äöü<a>
yes, no no
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

BaseX provides some additional, implementation-specific serialization parameters (the csv and json parameters may be subject to change):

Parameter Description Allowed Default
csv-header Indicates if the input contains a header row. Version 7.7.2 yes, no no
csv-separator Defines the character which separates fields in a row. Version 7.7.2 single character ,
json-spec Determines the used JSON specification. Version 7.7.2 RFC4627, ECMA-262, liberal RFC4627
json-unescape Determines whether escape sequences (marked by a backslash) in the input are expanded. Version 7.7.2 yes, no yes
json-format Determines the conversion format. Version 7.7.2 json, jsonml json
format Turns output formatting on/off, including the conversion of special characters to entities and insertion of item separators. yes, no yes
tabulator Uses tab characters (\t) for indenting elements. yes, no no
indents Specifies the number of characters to be indented. positive number 2
wrap-prefix,
wrap-uri
Specifies a prefix and/or URI for wrapping the query results.
newline Specifies the type of newline to be used as end-of-line marker. \n, \r\n, \r system dependent

Changelog

Version 7.8
  • Removed: separator option (use item-separator instead)
Version 7.7.2
  • Added: csv serialization method
  • Added: temporary serialization methods csv-header, csv-separator, json-unescape, json-spec, json-format
Version 7.5
  • Added: official item-separator and html-version parameter
  • Updated: method=html5 removed; serializers updated with the latest version of the specification, using method=html and version=5.0.
Version 7.2
  • Added: separator parameter
Version 7.1
  • Added: newline parameter
Version 7.0
  • Added: Serialization parameters added to REST API; JSON/JsonML/raw methods