On this page:
srl: sxml->xml
srl: sxml->xml-noindent
srl: sxml->html
srl: sxml->html-noindent

3 Serialization

(srl:sxml->xml sxml-obj)  string?
  sxml-obj : sxml?
(srl:sxml->xml sxml-obj dest)  void?
  sxml-obj : sxml?
  dest : (or/c output-port? string?)
Serializes the SXML node or nodeset sxml-obj into XML, with indentation to facilitate readability by a human.

If dest is not supplied, the function returns a string that contains the serialized representation of the sxml-obj. If dest is supplied and is a port, the functions write the serialized representation of sxml-obj to this port. If dest 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. If a file with the given name already exists, the effect is unspecified.

Examples:

> (srl:sxml->xml '(zippy (pippy (@ (pigtails "2")) "ab") "bc"))

"<zippy><pippy pigtails=\"2\">ab</pippy>bc</zippy>"

> (srl:sxml->xml '(zippy (pippy (@ (pigtails "2")) "ab") "bc")
                 (current-output-port))

<zippy><pippy pigtails="2">ab</pippy>bc</zippy>

> (srl:sxml->xml (for/fold ([body '(nothing)]) ([i (in-range 5)])
                   `(doll (@ (level ,(number->string i))) ,body))
                 (current-output-port))

<doll level="4">

  <doll level="3">

    <doll level="2">

      <doll level="1">

        <doll level="0">

          <nothing />

        </doll>

      </doll>

    </doll>

  </doll>

</doll>

(srl:sxml->xml-noindent sxml-obj)  string?
  sxml-obj : sxml?
(srl:sxml->xml-noindent sxml-obj dest)  void?
  sxml-obj : sxml?
  dest : (or/c output-port? string?)
Like srl:sxml->xml but without indentation.

Examples:

> (srl:sxml->xml-noindent
   '(zippy (pippy (@ (pigtails "2")) "ab") "bc"))

"<zippy><pippy pigtails=\"2\">ab</pippy>bc</zippy>"

> (srl:sxml->xml-noindent
   '(zippy (pippy (@ (pigtails "2")) "ab") "bc")
   (current-output-port))

<zippy><pippy pigtails="2">ab</pippy>bc</zippy>

> (srl:sxml->xml-noindent
   (for/fold ([body '(nothing)]) ([i (in-range 5)])
     `(doll (@ (level ,(number->string i))) ,body))
   (current-output-port))

<doll level="4"><doll level="3"><doll level="2"><doll level="1"><doll level="0"><nothing /></doll></doll></doll></doll></doll>

(srl:sxml->html sxml-obj)  string?
  sxml-obj : sxml?
(srl:sxml->html sxml-obj dest)  void?
  sxml-obj : sxml?
  dest : (or/c output-port? string?)
Serializes the SXML node or nodeset sxml-obj into HTML, with indentation to facilitate readability by a human.

If dest is not supplied, the functions return a string that contains the serialized representation of the sxml-obj. If dest is supplied and is a port, the functions write the serialized representation of sxml-obj to this port. If dest 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. If a file with the given name already exists, the effect is unspecified.

(srl:sxml->html-noindent sxml-obj)  string?
  sxml-obj : sxml?
(srl:sxml->html-noindent sxml-obj dest)  void?
  sxml-obj : sxml?
  dest : (or/c output-port? string?)
Like srl:sxml->html but without indentation.