Skip to content

Latest commit

 

History

History
76 lines (64 loc) · 2.31 KB

0064-xml-emitter.org

File metadata and controls

76 lines (64 loc) · 2.31 KB

xml-emitter

This library can be used to generate XML. You can use it for outputting any XML, but I use its builtin helpers to generate RSS feed.

Here is how to generate RSS feed in Common Lisp:

POFTHEDAY> (with-output-to-string (s)
             (xml-emitter:with-rss2 (s :encoding "utf-8")
               (xml-emitter:rss-channel-header "Common Lisp Project of the Day" 
                                               "https://poftheday.org")
               (xml-emitter:rss-item "First post"
                                     :description "Hello World"
                                     :category "lisp")))

"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<rss version=\"2.0\">
    <channel>
        <title>Common Lisp Project of the Day</title>
        <link>https://poftheday.org</link>
        <generator>xml-emitter</generator>
        <language>en-us</language>
        <item>
            <title>First post</title>
            <description>Hello World</description>
            <category>lisp</category>
        </item>
    </channel>
</rss>"

Of cause, you easily can generate any XML as well:

POFTHEDAY> (with-output-to-string (s)
             (xml-emitter:with-xml-output (s)
               (xml-emitter:with-tag ("address-book")
                 (xml-emitter:with-tag ("contact")
                   (xml-emitter:emit-simple-tags
                    :name "Bob"
                    :email "[email protected]"
                    :note "My friend."))
                 (xml-emitter:with-tag ("contact")
                   (xml-emitter:emit-simple-tags
                    :name "Mary"
                    :twitter "https://twitter.com/mary")))))

"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<address-book>
    <contact>
        <name>Bob</name>
        <email>[email protected]</email>
        <note>My friend.</note>
    </contact>
    <contact>
        <name>Mary</name>
        <twitter>https://twitter.com/mary</twitter>
    </contact>
</address-book>"

Please, note that support for XML namespaces is very limited. You can only specify a namespace for some tags. Namespace prefixes are not supported.