Created
February 19, 2012 18:43
-
-
Save DerGuteMoritz/1865111 to your computer and use it in GitHub Desktop.
Example code for ssax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<!-- <!DOCTYPE poem SYSTEM "dolor.dtd"> --> | |
<poem> | |
<title>Dolor</title> | |
<!-- Here's a simple example of an XML document --> | |
<author> | |
<last>Roethke</last> | |
<first>Theodore</first> | |
</author> | |
<linegroup> | |
<l n="1">I have known the inexorable sadness of pencils,</l> | |
<l n="2">Neat in their boxes, dolor of pad and paper-weight,</l> | |
<l n="3">All the misery of manila folders and mucilage,</l> | |
<l n="4">Desolation in immaculate public places,</l> | |
<l n="5">Lonely reception room, lavatory, switchboard,</l> | |
<l n="6">unalterable pathos of basin and pitcher,</l> | |
<l n="7">Ritual of multigraph, paper-clip, comma,</l> | |
<l n="8">Endless duplication of lives and objects.</l> | |
<l n="9">And I have seen dust from the walls of institutions,</l> | |
<l n="10">Finer than flour, alive, more dangerous than silica,</l> | |
<l n="11">Sift, almost invisible, through long afternoons of tedium,</l> | |
<l n="12">Dropping a fine film on nails and delicate eyebrows,</l> | |
<l n="13">Glazing the pale hair, the duplicate grey standard faces.</l> | |
</linegroup> | |
</poem> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use ssax) | |
(define read-outline | |
(let ((parser (ssax:make-parser | |
NEW-LEVEL-SEED | |
(lambda (elem-gi attrs namespaces expected-content seed) | |
(printf "~A<~A~A>~%" | |
seed | |
(tag->string elem-gi) | |
(format-attrs attrs)) | |
(string-append " " seed)) ; advance the indent level | |
FINISH-ELEMENT | |
(lambda (elem-gi attributes namespaces parent-seed seed) | |
parent-seed) ; restore the indent level | |
CHAR-DATA-HANDLER | |
(lambda (s1 s2 seed) | |
(when (> (string-length s1) 30) | |
(printf "~A|~A...~%" | |
seed | |
(substring s1 0 30))) | |
seed)))) | |
(lambda (port) | |
(parser port "")))) | |
(display (call-with-input-file "dolor.xml" read-outline)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment