Description

The lazy-ssax lazy XML->SXML parser.

Author

Dmitry Lizorkin

Version

Usage

(require-extension lazy-ssax)

Requires

Download

lazy-ssax.egg

Documentation

This egg provides Dmitry Lizorkin's lazy-ssax XML->SXML parser, which is a part of the SSAX toolkit. It is heavily based on continuations and promises. This code and API are preliminary.

This extension is built upon the XML parsing facilities of the ssax egg. In addition, other complementary lazy tools, such as lazy:sxpath, can be found in the sxml-tools-extra extension.

Main API

procedure: (lazy:xml->sxml port namespace-prefix-assig)
Produces a lazy SXML document, which corresponds to reading a source document in a stream-wise fashion.

Helper functions

procedure: lazy:force-descendants
A helper that forces all descendants of a given node or a nodeset.
procedure: lazy:except-last
Returns the list containing all members of the argument list, except for the last member.
procedure: (lazy:seed-common seed)
Returns the common part of the seed.
procedure: (lazy:replace-common seed new-common)
A monad-like handler. Replaces the common part of the seed.

Examples

This example is derived from the SSAX test suite, and is included inside the egg as test.scm, along with the input file poem.xml. Untar the egg to access the example.

(use lazy-ssax)
(use sxml-tools-extra)

(print "--- Lazy XML-to-SXML conversion")
(define doc (lazy:xml->sxml (open-input-file "poem.xml") '()))
(pp doc)

(print "--- Forced promise")
(pp (force (cadddr (caddr doc))))

(print "--- Querying a lazy SXML document, lazily")
(define res ((lazy:sxpath "poem/stanza/line[1]") doc))
(pp res)

(print "--- Obtain the next portion of the result")
(pp (force (cadr res)))

(print "--- Converting the lazy result to a conventional SXML nodeset")
(pp (lazy:result->list res))

Example input:

<?xml version='1.0'?>
<poem title="The Lovesong of J. Alfred Prufrock"
      poet="T. S. Eliot">
 <stanza>
  <line>Let us go then, you and I,</line>
  <line>When the evening is spread out against the sky</line>
  <line>Like a patient etherized upon a table:</line>
 </stanza>
 <stanza>
  <line>In the room the women come and go</line>
  <line>Talking of Michaelangelo.</line>
 </stanza>
</poem>

Example output:

--- Lazy XML-to-SXML conversion
(*TOP* (*PI* xml "version='1.0'")
      (poem (@ (title "The Lovesong of J. Alfred Prufrock")
               (poet "T. S. Eliot"))
            (stanza (line "Let us go then, you and I,") #<promise>)
            #<promise>))
--- Forced promise
((stanza (line "In the room the women come and go") #<promise>) #<promise>)
--- Querying a lazy SXML document, lazily
((line "Let us go then, you and I,") #<promise>)
--- Obtain the next portion of the result
((line "In the room the women come and go") #<promise>)
--- Converting the lazy result to a conventional SXML nodeset
((line "Let us go then, you and I,")
 (line "In the room the women come and go"))

License

The SSAX code is in the public domain.

Ported to Chicken by Zbigniew.