XML Output - MIT/GNU Scheme 9.1
Description: MIT/GNU Scheme 9.1

Next: XML Names, Previous: XML Input, Up: XML Support

#### 14.12.2 XML Output

The following procedures serialize XML document records into character sequences. All are virtually identical except for the way that the character sequence is represented.

Each procedure will accept either an `xml-document` record or any of the other XML record types. This makes it possible to write fragments of XML documents, although you should keep in mind that such fragments aren't documents and won't generally be accepted by any XML parser.

If the xml being written is an `xml-document` record, the procedures `write-xml` and `write-xml-file` will look for a contained `xml-declaration` record and its `encoding` attribute. If the `encoding` is a supported value, the output will be encoded as specified; otherwise it will be encoded as UTF-8.

When an XHTML document record is written, named XHTML characters are translated into their corresponding entities. For example, the character ``#\U+00A0`' is written as ``&nbsp;`'. In order for an XML document record to be recognized as XHTML, it must have a DTD record that satisfies the predicate `html-dtd?`.

— procedure: write-xml xml port

> Write xml to port. Note that character encoding will only be done if port supports it.

— procedure: write-xml-file xml pathname

> Write xml to the file specified by pathname. Roughly equivalent to

>               (define (write-xml-file xml pathname)
>                 (call-with-output-file pathname
>                   (lambda (port)
>                     (write-xml xml port))))

— procedure: xml->wide-string xml

> Convert xml to a wide string. No character encoding is used, since wide strings can represent all characters without encoding. Roughly equivalent to

>               (define (xml->wide-string xml)
>                 (call-with-wide-output-string
>                  (lambda (port)
>                    (write-xml xml port))))

— procedure: xml->string xml

> Convert xml to a character string encoded as UTF-8. Roughly equivalent to

>               (define (xml->string xml)
>                 (wide-string->utf8-string (xml->wide-string xml)))