pithy-xml
Read and write XML as lisp objects. Syntax somewhat similar to that of CL-WHO.

Repository: https://github.com/frodef/pithy-xml

License: BSD 3-Clause

Quick assessment (2023-04-08)

Nice lightweight parser—provided the case sensitivity of XML isn't too hairy. The mapping to Lisp symbols is designed for ease of use.

The read-xml function looks for an element matching a particular type—defaulting to a wildcard. An XML declaration parses like this:

> (pithy-xml:read-xml "<?xml version=\"1.0\" encoding=\"utf-8\"?>") ((:?XML :VERSION "1.0" :ENCODING "utf-8"))

Defining an XML namespace defines a package of that name for interning:

> (pithy-xml:define-xml-namespace :atom "http://www.w3.org/2005/Atom") :ATOM

Then we can read elements in a particular namespace:

> (pithy-xml:read-xml "<feed xmlns=\"http://www.w3.org/2005/Atom\"><title>Example Feed</title></feed>") ((ATOM::FEED :XMLNS "http://www.w3.org/2005/Atom") (ATOM::TITLE "Example Feed"))

And then we can go the other way:

> (pithy-xml:print-xml *) "<Feed xmlns='http://www.w3.org/2005/Atom'> <Title>Example Feed</Title> </Feed>"

Note that some names were capitalized in translation. Two functions map between XML and Lisp naming conventions:

> (pithy-xml:xml-intern "FooBar") :FOO-BAR > (format t "Upper camel: ~/pithy-xml:camel/~%~ Lower camel: ~@/pithy-xml:camel/~%" * *) Upper camel: FooBar Lower camel: fooBar NIL