SXML parsing for Common Lisp

Upstream URL


Bob Uhl <>


GNU General Public License


CL-SXML implements Oleg Kiselyov's SXML, an S-expression-basedrendering of the XML Infoset. It requires CXML for SAX parsing.

CL-SXML is developed on SBCL, but it has been successfully tested on Allegro CL, LispWorks, Clozure & CLISP. It does not currently work with ECL.

Note: CXML:PARSE behaves differently with different implementations. With SBCL & Allegro CL, one can just pass it a string to parse; with LispWorks one must call RUNES:UTF8-STRING-TO-ROD.


1.1.1Class SXML-HANDLER precedence list

sax:default-handler, sax:content-handler, sax:abstract-handler,sax:sax-parser-mixin, standard-object, t

A CXML SAX handler which produces SXML documents. The constructortakes a single initarg, :PACKAGE (defaults to *PACKAGE*), whichspecifies the package to intern symbols into.

An interesting omission in the SXML spec is no support for the XML DOCTYPE declaration. The spec does provide for optional annotations, though, and so I've chosen to use a *DOCTYPE* annotation to hold that information. This may change in the future.

Note that all whitespace is preserved, as required by the XML spec. This is ugly — yet more proof that S-expressions are preferable to XML.

(cxml:parse "<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Document PUBLIC '-//foo.example//An Example//EN' 'http://foo.example/'>
<?top-level here's a top-level processing instruction?>
<doc xmlns:h=''>
<h:p class='bar'>Here is some text.</h:p>
            (make-instance 'cl-sxml:sxml-handler)
            :entity-resolver (lambda (p s)
                               (declare (ignorable p s))
                               (flexi-streams:make-in-memory-input-stream nil)))


  (*DOCTYPE* "Document" "-//foo.example//An Example//EN"
 (*pi* |top-level| "here's a top-level processing instruction")
     (|| "" |h|))))
  (|| "
   (|| "
    (|| (@ (|class| "bar"))
     "Here is some text.")

Dependencies (4)

  • cxml
  • fiveam
  • flexi-streams
  • uiop

Dependents (1)

  • GitHub
  • Quicklisp