<?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>What I Learned Today &#187; xml</title>
	<atom:link href="http://christiansons.net/mike/blog/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://christiansons.net/mike/blog</link>
	<description>Mike Christianson&#039;s journal of Java, Ant, SVN, Jetty, cygwin and other stuff.</description>
	<lastBuildDate>Wed, 04 Aug 2010 22:24:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Pretty XML from XOM</title>
		<link>http://christiansons.net/mike/blog/2008/11/pretty-xml-from-xom/</link>
		<comments>http://christiansons.net/mike/blog/2008/11/pretty-xml-from-xom/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 23:44:54 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=13</guid>
		<description><![CDATA[Getting nicely indented XML from XOM as a String is not intuitive. One might reasonably expect to try document.toXML() only to find the output lacking indentation. Here&#8217;s how I used XOM&#8217;s Serializer and Java&#8217;s ByteArrayOutputStream to produce pretty XML. 1 2 3 4 5 ByteArrayOutputStream out = new ByteArrayOutputStream&#40;&#41;; Serializer serializer = new Serializer&#40;out, &#34;UTF-8&#34;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Getting nicely indented XML from <a title="XOM is a &quot;...tree-based API for processing XML with Java that strives for correctness, simplicity, and performance, in that order.&quot;" href="http://xom.nu/">XOM</a> as a String is not intuitive.  One might reasonably expect to try <a title="Javadoc for toXML()" href="http://xom.nu/apidocs/nu/xom/Document.html#toXML()"><tt>document.toXML()</tt></a> only to find the output lacking indentation.</p>
<p>Here&#8217;s how I used XOM&#8217;s <a title="Javadoc for Serializer" href="http://xom.nu/apidocs/nu/xom/Serializer.html">Serializer</a> and Java&#8217;s <a title="Javadoc for ByteArrayOutputStream" href="http://java.sun.com/javase/6/docs/api/java/io/ByteArrayOutputStream.html"><tt>ByteArrayOutputStream</tt></a> to produce pretty XML.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">ByteArrayOutputStream</span> out <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Serializer serializer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serializer<span style="color: #009900;">&#40;</span>out, <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
serializer.<span style="color: #006633;">setIndent</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
serializer.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> xml <span style="color: #339933;">=</span> out.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/11/pretty-xml-from-xom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
