For Gauche 0.9.15Search (procedure/syntax/module):

Next: , Previous: , Up: Library modules - Utilities   [Contents][Index]

12.62 sxml.serializer - Serializing XML and HTML from SXML

Module: sxml.serializer

This module contains a full-featured serializer from SXML into XML and HTML, partially conforming to XSLT 2.0 and XQuery 1.0 Serialization (http://www.w3.org/TR/2005/CR-xslt-xquery-serialization-20051103/). It’s more powerful than sxml:sxml->xml and sxml:sxml->html from sxml.tools.

The manual entry is mainly derived from the comments in the original source code.


12.62.1 Simple SXML serializing

The SXML serializer provides some convenient high-level converters which should be enough for most tasks.

Function: srl:sxml->xml sxml-obj :optional port-or-filename

{sxml.serializer} Serializes the sxml-obj into XML, with indentation to facilitate readability by a human.

If port-or-filename is not supplied, the functions return a string that contains the serialized representation of the sxml-obj.

If port-or-filename is supplied and is a port, the functions write the serialized representation of sxml-obj to this port and return an unspecified result.

If port-or-filename is supplied and is a string, this string is treated as an output filename, the serialized representation of sxml-obj is written to that filename and an unspecified result is returned. If a file with the given name already exists, the effect is unspecified.

Note: Unlike sxml:sxml->xml in sxml.ssax, this procedure requires XML attribute values to be strings.

Function: srl:sxml->xml-noindent sxml-obj :optional port-or-filename

{sxml.serializer} Serializes the sxml-obj into XML, without indentation.

Argument port-or-filename works like described in srl:sxml->xml.

Function: srl:sxml->html sxml-obj :optional port-or-filename

{sxml.serializer} Serializes the sxml-obj into HTML, with indentation to facilitate readability by a human.

Argument port-or-filename works like described in srl:sxml->xml.

Note: Unlike sxml:sxml->html in sxml.ssax, this procedure requires XML attribute values to be strings.

Function: srl:sxml->html-noindent sxml-obj :optional port-or-filename

{sxml.serializer} Serializes the sxml-obj into HTML, without indentation.

Argument port-or-filename works like described in srl:sxml->xml.


12.62.2 Custom SXML serializing

These functions provide full access to all configuration parameters of the XML serializer.

Function: srl:parameterizable sxml-obj :optional port-or-filename params*

{sxml.serializer} Generalized serialization procedure, parameterizable with all the serialization parameters supported by this implementation.

sxml-obj - an SXML object to serialize

port-or-filename - either #f, a port or a string; works like in srl:sxml->xml (Simple SXML serializing).

params - each parameter is a cons of param-name (a symbol) and param-value. The available parameter names and their values are described below:

method - Either the symbol xml or html. For a detailed explanation of the difference between XML and HTML methods, see XSLT 2.0 and XQuery 1.0 Serialization (http://www.w3.org/TR/2005/CR-xslt-xquery-serialization-20051103/).

indent - Whether the output XML should include whitespace for human readability (#t or #f). You can also supply a string, which will be used as the indentation unit.

omit-xml-declaration - Whether the XML declaration should be omitted. Default: #t.

standalone - Whether to define the XML document as standalone in the XML declaration. Should be one of the symbols yes, no or omit, the later causing standalone declaration to be suppressed. Default: omit.

version - The XML version used in the declaration. A string or a number. Default: "1.0".

cdata-section-elements - A list of SXML element names (as symbols). The contents of those elements will be escaped as CDATA sections.

ns-prefix-assig - A list of (cons prefix namespace-uri), where each prefix is a symbol and each namespace-uri a string. Will serialize the given namespaces with the corresponding prefixes.

ATTENTION: If a parameter name is unexpected or a parameter value is ill-formed, the parameter is silently ignored!

Example usage:

(srl:parameterizable
  '(tag (@ (attr "value")) (nested "text node") (empty))
  (current-output-port)
  '(method . xml)  ; XML output method is used by default
  '(indent . "\t")  ; use a single tabulation to indent
  '(omit-xml-declaration . #f)  ; add XML declaration
  '(standalone . yes)  ; denote a standalone XML document
  '(version . "1.0"))  ; XML version
param ::= (cons param-name param-value)
param-name ::= symbol

cdata-section-elements
value ::= (listof sxml-elem-name)
sxml-elem-name ::= symbol

indent
value ::= 'yes | #t | 'no | #f | whitespace-string

method
value ::= 'xml | 'html

ns-prefix-assig
value ::= (listof (cons prefix namespace-uri))
prefix ::= symbol
namespace-uri ::= string

omit-xml-declaration
value ::= 'yes | #t | 'no | #f

standalone
value ::= 'yes | #t | 'no | #f | 'omit

version
value ::= string | number
Function: srl:sxml->string sxml-obj cdata-section-elements indent method ns-prefix-assig omit-xml-declaration? standalone version

{sxml.serializer} Same as srl:parameterizable returning a string and without the overhead of parsing parameters. This function interface may change in future versions of the library.

Function: srl:display-sxml sxml->obj port-or-filename cdata-section-elements indent method ns-prefix-assig omit-xml-declaration? standalone version

{sxml.serializer} Same as srl:parameterizable writing output to port-or-filename and without the overhead of parsing parameters. This function interface may change in future versions of the library.


Next: , Previous: , Up: Library modules - Utilities   [Contents][Index]


For Gauche 0.9.15Search (procedure/syntax/module):