100 lines
6.6 KiB
HTML
100 lines
6.6 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<title>CLiki: xml-emitter</title>
|
||
|
<link rel="alternate" type="application/atom+xml" title="ATOM feed of edits to current article"
|
||
|
href="https://www.cliki.net/site/feed/article.atom?title=xml-emitter">
|
||
|
<link rel="stylesheet" href="static/css/style.css">
|
||
|
<link rel="stylesheet" href="static/css/colorize.css">
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
<span class="hidden">CLiki - xml-emitter</span>
|
||
|
<div id="content"><div id="content-area"><div id="article-title">xml-emitter</div><div id="article">Often, programs have to generate <a href="XML.html" class="category">XML</a> output. This is fairly easy, but
|
||
|
not quite trivial. You need to do escaping, and indentation can be a
|
||
|
little tricky to keep track of. One approach you could use is to get
|
||
|
an XML parser/unparser like <a href="XMLS.html" class="internal">XMLS</a>, build your XML data structure in
|
||
|
memory, then dump the whole thing. This is fairly easy, but not as
|
||
|
easy as it could be, and it requires holding the whole structure in
|
||
|
memory.<p>So, I wrote xml-emitter. xml-emitter simply emits XML, with some
|
||
|
complexity for handling indentation. It can be used to produce all
|
||
|
sorts of useful XML output; it has an <a href="RSS.html" class="category">RSS</a> 2.0 emitter built in, so you can make RSS feeds trivially.<p>There is no real home page, but you can download it from the
|
||
|
<a href="http://common-lisp.net/project/asdf-packaging/">asdf-packaging project</a>. Or from the download link on this page.<p>If you have comments, questions, or bug reports, email them to <a href="Peter Scott.html" class="internal">Peter Scott</a> <a href="mailto:pscott@common-lisp.net"></a>.<p><b>Update (August 2015):</b><p><ul>
|
||
|
<li>Now there is an official repository: <a href="https://github.com/VitoVan/xml-emitter">xml-emitter</a> maintained by Vito Van, feel free to submit issues and pull requests.</li>
|
||
|
</ul><p>
|
||
|
<h2>Usage</h2><p>The WITH-XML-OUTPUT macro wraps all XML output to a stream.<p>The WITH-TAG macro places the XML produced by its body inside a
|
||
|
tag. Its output cannot be on just one line, since it puts starting and
|
||
|
closing tags on their own lines.<p>The WITH-SIMPLE-TAG macro is like WITH-TAG, but starting and closing
|
||
|
tags don't get their own lines.<p>XML-OUT prints its argument to the XML output stream, escaped.<p>XML-AS-IS prints its argument to the XML output stream, unescaped.<p>SIMPLE-TAG prints a simple <code><tag>value</tag></code> tag. It's a shortened
|
||
|
version of a typical use of WITH-SIMPLE-TAG and XML-OUT.<p>EMIT-SIMPLE-TAGS takes a plist of tag names and tag values. For every
|
||
|
tag with a non-NIL value, it prints the tag with SIMPLE-TAG. Tag names
|
||
|
given as keyword symbols (like <code>:this</code>) are downcased.<p><b>Example:</b><p><pre>
|
||
|
(with-xml-output (*standard-output*)
|
||
|
(with-tag ("person" '(("age" "19")))
|
||
|
(with-simple-tag ("firstName")
|
||
|
(xml-out "Peter"))
|
||
|
(simple-tag "lastName" "Scott")
|
||
|
(emit-simple-tags :age 17
|
||
|
:school "Iowa State Univeristy"
|
||
|
"mixedCaseTag" "Check out the mixed case!"
|
||
|
"notShown" nil)))
|
||
|
</pre><p><h2>The RSS 2.0 emitter</h2><p>The WITH-RSS2 macro wraps up all output of RSS.<p>RSS-CHANNEL-HEADER outputs the RSS channel information.<p>RSS-ITEM outputs information about one RSS item.<p><b>Example:</b><p><pre>
|
||
|
(with-rss2 (*standard-output*)
|
||
|
(rss-channel-header "Peter's Blog" "http://peter.blogspot.com/"
|
||
|
:description "A place where I sometimes post stuff"
|
||
|
:image "myhead.jpg"
|
||
|
:image-title "My glorious visage")
|
||
|
(rss-item "Breaking news!"
|
||
|
:link "http://google.com/"
|
||
|
:description "The biggest problem with the DO-ODD macro above is that it puts BODY
|
||
|
into LOOP. Code from the user of the macro should never be run in the
|
||
|
environment established by the LOOP macro. LOOP does a number of
|
||
|
things behind your back, and it's hard to disable them. For example,
|
||
|
what happens here?"
|
||
|
:author "Peter Scott"
|
||
|
:category "Lisp"
|
||
|
:pubDate "Sun, 29 Sep 2002 19:59:01 GMT")
|
||
|
(rss-item "RSS emitter created"
|
||
|
:description "An RSS emitter has been released! Hahahahaha!"
|
||
|
:author "Peter Scott"
|
||
|
:link "http://gmail.google.com/"))
|
||
|
</pre><p>There is also a complete example of how you might use the RSS emitter
|
||
|
in <tt>mailbox.lisp</tt> in the source distribution.</div></div>
|
||
|
<div id="footer" class="buttonbar"><ul><li><a href="xml-emitter.html">Current version</a></li>
|
||
|
<li><a href="https://www.cliki.net/site/history?article=xml-emitter">History</a></li>
|
||
|
<li><a href="https://www.cliki.net/site/backlinks?article=xml-emitter">Backlinks</a></li><li><a href="https://www.cliki.net/site/edit-article?title=xml-emitter&from-revision=3686419757">Edit</a></li><li><a href="https://www.cliki.net/site/edit-article?create=t">Create</a></li></ul></div>
|
||
|
</div>
|
||
|
<div id="header-buttons" class="buttonbar">
|
||
|
<ul>
|
||
|
<li><a href="https://www.cliki.net/">Home</a></li>
|
||
|
<li><a href="https://www.cliki.net/site/recent-changes">Recent Changes</a></li>
|
||
|
<li><a href="CLiki.html">About</a></li>
|
||
|
<li><a href="Text Formatting.html">Text Formatting</a></li>
|
||
|
<li><a href="https://www.cliki.net/site/tools">Tools</a></li>
|
||
|
</ul>
|
||
|
<div id="search">
|
||
|
<form action="https://www.cliki.net/site/search">
|
||
|
<label for="search_query" class="hidden">Search CLiki</label>
|
||
|
<input type="text" name="query" id="search_query" value="" />
|
||
|
<input type="submit" value="search" />
|
||
|
</form>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div id="pageheader">
|
||
|
<div id="header">
|
||
|
<span id="logo">CLiki</span>
|
||
|
<span id="slogan">the common lisp wiki</span>
|
||
|
<div id="login"><form method="post" action="https://www.cliki.net/site/login">
|
||
|
<label for="login_name" class="hidden">Account name</label>
|
||
|
<input type="text" name="name" id="login_name" class="login_input" />
|
||
|
<label for= "login_password" class="hidden">Password</label>
|
||
|
<input type="password" name="password" id="login_password" class="login_input" />
|
||
|
<input type="submit" name="login" value="login" id="login_submit" /><br />
|
||
|
<div id="register"><a href="https://www.cliki.net/site/register">register</a></div>
|
||
|
<input type="submit" name="reset-pw" value="reset password" id="reset_pw" />
|
||
|
</form>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body></html>
|