Skip to content

eadmund/cl-sxml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CL-SXML

CL-SXML implements Oleg Kiselyov’s SXML, an S-expression-based rendering 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.

API

Class SXML-HANDLER

Class precedence list

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

Description

A CXML SAX handler which produces SXML documents. The constructor takes a single initarg, :PACKAGE (defaults to *PACKAGE*), which specifies 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.

Example

(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='http://www.w3.org/1999/xhtml'>
<h:html>
<h:body>
<h:p class='bar'>Here is some text.</h:p>
</h:body></h:html></doc>"
            (make-instance 'cl-sxml:sxml-handler)
            :entity-resolver (lambda (p s)
                               (declare (ignorable p s))
                               (flexi-streams:make-in-memory-input-stream nil)))

Yields:

(*TOP*
 (@
  (*DOCTYPE* "Document" "-//foo.example//An Example//EN"
   "http://foo.example/"))
 (*pi* |top-level| "here's a top-level processing instruction")
 (|doc|
  (@
   (@
    (*namespaces*
     (|http://www.w3.org/1999/xhtml| "http://www.w3.org/1999/xhtml" |h|))))
  "
"
  (|http://www.w3.org/1999/xhtml:html| "
"
   (|http://www.w3.org/1999/xhtml:body| "
"
    (|http://www.w3.org/1999/xhtml:p| (@ (|class| "bar"))
     "Here is some text.")
    "
"))))

About

XML in S-expressions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published