The lazy-ssax lazy XML->SXML parser.
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.
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"))