<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Pretty Printing XML</title>
	<atom:link href="http://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/</link>
	<description>Leveraging Perl and Emacs</description>
	<lastBuildDate>Tue, 07 May 2013 11:25:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Tim Bergsma</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/#comment-8971</link>
		<dc:creator><![CDATA[Tim Bergsma]]></dc:creator>
		<pubDate>Fri, 13 May 2011 15:19:56 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=276#comment-8971</guid>
		<description><![CDATA[(Apologies for the mangled example above.  Subroutine looks mostly ok except for a fancy double quote that should be plain.)]]></description>
		<content:encoded><![CDATA[<p>(Apologies for the mangled example above.  Subroutine looks mostly ok except for a fancy double quote that should be plain.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Bergsma</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/#comment-8970</link>
		<dc:creator><![CDATA[Tim Bergsma]]></dc:creator>
		<pubDate>Fri, 13 May 2011 15:14:50 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=276#comment-8970</guid>
		<description><![CDATA[I like the Twig output, but needed a subroutine version and couldn&#039;t assume availability of XML::Twig for my end-users.  Here&#039;s a light-weight xml pretty printer implemented as a subroutine.  It excepts a single string, possibly with embedded newline, and returns a single string, certainly with embedded newline.  Embedded &quot;less than&quot; in input must be properly escaped.

sub pretty{
	$_ = shift;
	# Put a newline before every &#039;open&#039; tag.
	s&quot;(&lt;[^/])&quot;\n$1&quot;g;
	# Eliminate duplicate newline.
	s&quot;[\n]{2,}(\n])\n&lt;/&quot;$1&lt;/&quot;g;
	# Now we have lines the way we like them.
	# It remains only to calculate indentations.
	my @lines = split(&#039;\n&#039;,$_);
	my $depth = -1;
	foreach my $line (@lines){
		# If line starts with an open tag, increase depth.
		$depth+=1 if $line=~&#039;^)&#124;(&lt;/)&#039;;
	}
	$_ = join &quot;\n&quot;, @lines;
	$_ = $_ . &quot;\n&quot;;
	$_
}

pretty(&quot;&lt;a&gt;&lt;b&gt;text&lt;/b&gt;&lt;b /&gt;&lt;/a&gt;&quot;)

... gives ...

&lt;a&gt;
 &lt;b&gt;
  text
 &lt;/b&gt;
 &lt;b /&gt;
&lt;/a&gt;]]></description>
		<content:encoded><![CDATA[<p>I like the Twig output, but needed a subroutine version and couldn&#8217;t assume availability of XML::Twig for my end-users.  Here&#8217;s a light-weight xml pretty printer implemented as a subroutine.  It excepts a single string, possibly with embedded newline, and returns a single string, certainly with embedded newline.  Embedded &#8220;less than&#8221; in input must be properly escaped.</p>
<p>sub pretty{<br />
	$_ = shift;<br />
	# Put a newline before every &#8216;open&#8217; tag.<br />
	s&#8221;(&lt;[^/])&quot;\n$1&quot;g;<br />
	# Eliminate duplicate newline.<br />
	s&quot;[\n]{2,}(\n])\n&lt;/&quot;$1&lt;/&quot;g;<br />
	# Now we have lines the way we like them.<br />
	# It remains only to calculate indentations.<br />
	my @lines = split(&#039;\n&#039;,$_);<br />
	my $depth = -1;<br />
	foreach my $line (@lines){<br />
		# If line starts with an open tag, increase depth.<br />
		$depth+=1 if $line=~&#039;^)|(&lt;/)&#039;;<br />
	}<br />
	$_ = join &quot;\n&quot;, @lines;<br />
	$_ = $_ . &quot;\n&quot;;<br />
	$_<br />
}</p>
<p>pretty(&quot;<a><b>text</b><b></b></a>&#8220;)</p>
<p>&#8230; gives &#8230;</p>
<p><a><br />
 <b><br />
  text<br />
 </b><br />
 <b></b><br />
</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/#comment-7297</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Sat, 28 Feb 2009 10:19:51 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=276#comment-7297</guid>
		<description><![CDATA[Hi Matt,

It looks like that snippet is quite widely used - it is the same one as at &lt;a href=&quot;http://blog.bookworm.at/2007/03/pretty-print-xml-with-emacs.html&quot; rel=&quot;nofollow&quot;&gt;http://blog.bookworm.at/2007/03/pretty-print-xml-with-emacs.html&lt;/a&gt;.

I tested it and I do prefer the indentation slightly over &lt;em&gt;(sgml-pretty-print ...)&lt;/em&gt; but I still need &lt;em&gt;join-broken-lines&lt;/em&gt; for when my cut and paste breaks a tag in the middle.  E.g.

&lt;ab
cd&gt;
....
&lt;/abcd&gt;
]]></description>
		<content:encoded><![CDATA[<p>Hi Matt,</p>
<p>It looks like that snippet is quite widely used &#8211; it is the same one as at <a href="http://blog.bookworm.at/2007/03/pretty-print-xml-with-emacs.html" rel="nofollow">http://blog.bookworm.at/2007/03/pretty-print-xml-with-emacs.html</a>.</p>
<p>I tested it and I do prefer the indentation slightly over <em>(sgml-pretty-print &#8230;)</em> but I still need <em>join-broken-lines</em> for when my cut and paste breaks a tag in the middle.  E.g.</p>
<p>&lt;ab<br />
cd&gt;<br />
&#8230;.<br />
&lt;/abcd&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: matt harrison</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/#comment-7296</link>
		<dc:creator><![CDATA[matt harrison]]></dc:creator>
		<pubDate>Sat, 28 Feb 2009 07:36:44 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=276#comment-7296</guid>
		<description><![CDATA[I use the following in my .emacs with nxml.  Note that I need to select the entire buffer first before invoking it.


(defun indent-xml-region (begin end)
  &quot;Pretty format XML markup in region. You need to have nxml-mode
http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
this.  The function inserts linebreaks to separate tags that have
nothing but whitespace between them.  It then indents the markup
by using nxml&#039;s indentation rules.&quot;
  (interactive &quot;r&quot;)
  (save-excursion
    (nxml-mode)
    (goto-char begin)
    (while (search-forward-regexp &quot;\&gt;[ \\t]*\&lt;&quot; nil t)
      (backward-char) (insert &quot;\n&quot;)
      )
    (mark-whole-buffer)
    (indent-region begin end)
    ;(indent-region point-min point-max)
    )
  (message &quot;Ah, much better!&quot;))
]]></description>
		<content:encoded><![CDATA[<p>I use the following in my .emacs with nxml.  Note that I need to select the entire buffer first before invoking it.</p>
<p>(defun indent-xml-region (begin end)<br />
  &#8220;Pretty format XML markup in region. You need to have nxml-mode<br />
<a href="http://www.emacswiki.org/cgi-bin/wiki/NxmlMode" rel="nofollow">http://www.emacswiki.org/cgi-bin/wiki/NxmlMode</a> installed to do<br />
this.  The function inserts linebreaks to separate tags that have<br />
nothing but whitespace between them.  It then indents the markup<br />
by using nxml&#8217;s indentation rules.&#8221;<br />
  (interactive &#8220;r&#8221;)<br />
  (save-excursion<br />
    (nxml-mode)<br />
    (goto-char begin)<br />
    (while (search-forward-regexp &#8220;\&gt;[ \\t]*\&lt;&#8221; nil t)<br />
      (backward-char) (insert &#8220;\n&#8221;)<br />
      )<br />
    (mark-whole-buffer)<br />
    (indent-region begin end)<br />
    ;(indent-region point-min point-max)<br />
    )<br />
  (message &#8220;Ah, much better!&#8221;))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/#comment-7291</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Fri, 27 Feb 2009 08:54:34 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=276#comment-7291</guid>
		<description><![CDATA[Hi Keegan,

Yes, I did see that article when I searching for similar posts.  I think (bf-pretty-print-xml-region ...) has an equivalent in sgml mode now - (sgml-pretty-print ...)]]></description>
		<content:encoded><![CDATA[<p>Hi Keegan,</p>
<p>Yes, I did see that article when I searching for similar posts.  I think (bf-pretty-print-xml-region &#8230;) has an equivalent in sgml mode now &#8211; (sgml-pretty-print &#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keegan</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/#comment-7290</link>
		<dc:creator><![CDATA[Keegan]]></dc:creator>
		<pubDate>Fri, 27 Feb 2009 06:30:09 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=276#comment-7290</guid>
		<description><![CDATA[Have you seen http://blog.bookworm.at/2007/03/pretty-print-xml-with-emacs.html]]></description>
		<content:encoded><![CDATA[<p>Have you seen <a href="http://blog.bookworm.at/2007/03/pretty-print-xml-with-emacs.html" rel="nofollow">http://blog.bookworm.at/2007/03/pretty-print-xml-with-emacs.html</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
