<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>therning.org/ magnus &#187; xml</title>
	<atom:link href="http://therning.org/magnus/archives/tag/xml/feed" rel="self" type="application/rss+xml" />
	<link>http://therning.org/magnus</link>
	<description>Incoherent mumblings</description>
	<lastBuildDate>Thu, 12 Jan 2012 13:40:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>XML character dereferencer</title>
		<link>http://therning.org/magnus/archives/828</link>
		<comments>http://therning.org/magnus/archives/828#comments</comments>
		<pubDate>Fri, 13 Aug 2010 14:30:38 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=828</guid>
		<description><![CDATA[Just in case you ever need one: xmlCharDeref :: String -&#62; String xmlCharDeref &#91;&#93; = &#91;&#93; xmlCharDeref &#40;'&#38;':'#':'x':r&#41; = let &#40;digits, remainder&#41; = span &#40;/= ';'&#41; r c = chr &#40;read &#40;&#34;0x&#34; ++ digits&#41;&#41; in c : xmlCharDeref &#40;tail remainder&#41; xmlCharDeref &#40;'&#38;':'#':r&#41; = let &#40;digits, remainder&#41; = span &#40;/= ';'&#41; r c = chr &#40;read [...]]]></description>
			<content:encoded><![CDATA[<p>Just in case you ever need one:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">xmlCharDeref <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
xmlCharDeref <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
xmlCharDeref <span style="color: green;">&#40;</span>'&amp;':'#':'x':r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: green;">&#40;</span>digits<span style="color: #339933; font-weight: bold;">,</span> remainder<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">span</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">/=</span> ';'<span style="color: green;">&#41;</span> r
        c <span style="color: #339933; font-weight: bold;">=</span> chr <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;0x&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> digits<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">in</span>
        c : xmlCharDeref <span style="color: green;">&#40;</span><span style="font-weight: bold;">tail</span> remainder<span style="color: green;">&#41;</span>
xmlCharDeref <span style="color: green;">&#40;</span>'&amp;':'#':r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: green;">&#40;</span>digits<span style="color: #339933; font-weight: bold;">,</span> remainder<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">span</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">/=</span> ';'<span style="color: green;">&#41;</span> r
        c <span style="color: #339933; font-weight: bold;">=</span> chr <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> digits<span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">in</span>
        c : xmlCharDeref <span style="color: green;">&#40;</span><span style="font-weight: bold;">tail</span> remainder<span style="color: green;">&#41;</span>
xmlCharDeref <span style="color: green;">&#40;</span>c:r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> c : xmlCharDeref r</pre></div></div>


<p>In ghci:</p>


<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">*Foo&gt; xmlCharDeref &quot;hello there&quot;
&quot;hello there&quot;
*Foo&gt; xmlCharDeref &quot;hello&amp;#32;there&quot;
&quot;hello there&quot;
*Foo&gt; xmlCharDeref &quot;hello&amp;#x32;there&quot;
&quot;hello2there&quot;</pre></div></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Ftherning.org%2Fmagnus%2Farchives%2F828&amp;title=XML%20character%20dereferencer" id="wpa2a_2">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/828/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XML prettifier in Haskell</title>
		<link>http://therning.org/magnus/archives/695</link>
		<comments>http://therning.org/magnus/archives/695#comments</comments>
		<pubDate>Tue, 14 Jul 2009 13:44:37 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=695</guid>
		<description><![CDATA[I don&#8217;t know how many times I&#8217;ve gone looking for one of these but my search-fu is weak and I always give up, instead resorting to manual editing in Vim (no I hardly ever need the entire file to be pretty, only one or two tags that I&#8217;m interested in). Anyway, here&#8217;s a quick hack [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know how many times I&#8217;ve gone looking for one of these but my search-fu is weak and I always give up, instead resorting to manual editing in Vim (no I hardly ever need the <em>entire</em> file to be pretty, only one or two tags that I&#8217;m interested in).  Anyway, here&#8217;s a quick hack in Haskell, relying on <a href="http://hackage.haskell.org/package/xml">xml</a> for the heavy lifting:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">#<span style="color: #339933; font-weight: bold;">!</span> <span style="color: #339933; font-weight: bold;">/</span>usr<span style="color: #339933; font-weight: bold;">/</span>bin<span style="color: #339933; font-weight: bold;">/</span>env runhaskell
&nbsp;
<span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Monad</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Environment
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>XML<span style="color: #339933; font-weight: bold;">.</span>Light<span style="color: #339933; font-weight: bold;">.</span>Input
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>XML<span style="color: #339933; font-weight: bold;">.</span>Light<span style="color: #339933; font-weight: bold;">.</span>Output
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    fn <span style="color: #339933; font-weight: bold;">&lt;-</span> liftM <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">!!</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> getArgs
    xml<span style="color: #339933; font-weight: bold;">_</span>contents <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">readFile</span> fn
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: green;">&#40;</span>Just doc<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> parseXMLDoc xml<span style="color: #339933; font-weight: bold;">_</span>contents
    <span style="font-weight: bold;">writeFile</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;pretty-&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> fn<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>ppTopElement doc<span style="color: green;">&#41;</span></pre></div></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Ftherning.org%2Fmagnus%2Farchives%2F695&amp;title=XML%20prettifier%20in%20Haskell" id="wpa2a_4">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/695/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

