<?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"
	>
<channel>
	<title>Comments on: Format XML with PHP</title>
	<atom:link href="http://recurser.com/articles/2007/04/05/format-xml-with-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/</link>
	<description></description>
	<pubDate>Thu, 04 Dec 2008 07:54:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
		<item>
		<title>By: David</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-912</link>
		<dc:creator>David</dc:creator>
		<pubDate>Tue, 25 Nov 2008 21:44:56 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-912</guid>
		<description>Really great function you wrote here.</description>
		<content:encoded><![CDATA[<p>Really great function you wrote here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-910</link>
		<dc:creator>Jamie</dc:creator>
		<pubDate>Fri, 14 Nov 2008 12:44:32 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-910</guid>
		<description>Thanks! Just added as a handy php macro for use in EditPlus text editor.</description>
		<content:encoded><![CDATA[<p>Thanks! Just added as a handy php macro for use in EditPlus text editor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gg2laba</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-890</link>
		<dc:creator>gg2laba</dc:creator>
		<pubDate>Sun, 21 Sep 2008 17:36:13 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-890</guid>
		<description>good one, some little problems for me :

- i added \s* to get reed of existing whitespaces :

// add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries)
  $xml = preg_replace('/(&#62;)\s*(&#60;)(\/*)/', "$1\n$2$3", $xml);

- i added $indent=0; too because the indent fail sometime for me ! :

    // 2. closing tag - outdent now
    elseif (preg_match('/^&#60;\/\w/', $token, $matches)) :
      $pad--;$indent=0;

thanks for this, made me win a lot of time.</description>
		<content:encoded><![CDATA[<p>good one, some little problems for me :<br />
 &#8211; i added \s* to get reed of existing whitespaces :</p>
<p>// add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries)<br />
  $xml = preg_replace(&#8217;/(>)\s*(< )(\/*)/&#8217;, &#8221;$1\n$2$3&#8221;, $xml);<br />
 &#8211; i added $indent=0; too because the indent fail sometime for me ! :</p>
<p>    // 2. closing tag &#8211; outdent now<br />
    elseif (preg_match(&#8217;/^< \/\w/&#8217;, $token, $matches)) :<br />
      $pad&#8212;;$indent=0;</p>
<p>thanks for this, made me win a lot of time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: emzet</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-886</link>
		<dc:creator>emzet</dc:creator>
		<pubDate>Fri, 19 Sep 2008 08:19:20 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-886</guid>
		<description>very nice, thanks!</description>
		<content:encoded><![CDATA[<p>very nice, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kg23</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-884</link>
		<dc:creator>kg23</dc:creator>
		<pubDate>Fri, 19 Sep 2008 00:31:36 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-884</guid>
		<description>You can also use the linux xmllint command as so...

public static function formatXmlString($xml) {  
	  $xml = escapeshellarg($xml);
	  $result = array();
	  exec('echo '.$xml.' &#124; xmllint --format -',$result);
	  $result = join("\n",$result);
	  return $result;	
}</description>
		<content:encoded><![CDATA[<p>You can also use the linux xmllint command as so&#8230;</p>
<p>public static function formatXmlString($xml) {<br />
  $xml = escapeshellarg($xml);<br />
  $result = array();<br />
  exec(&#8216;echo &#8217;.$xml.&#8217; | xmllint&#8212;format -&#8217;,$result);<br />
  $result = join(&#8221;\n&#8221;,$result);<br />
  return $result;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zaker</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-158</link>
		<dc:creator>zaker</dc:creator>
		<pubDate>Tue, 01 Jul 2008 08:34:16 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-158</guid>
		<description>*Custom padding*
1. Modify function declaration this way: function formatXmlString($xml, $padstr = " "); 

2. change $line declaration this way:
$line = str_repeat($padstr, $pad).$token;</description>
		<content:encoded><![CDATA[<p><strong>Custom padding</strong><br />
1. Modify function declaration this way: function formatXmlString($xml, $padstr = &#8221; &#8221;); </p>
<p>2. change $line declaration this way:<br />
$line = str_repeat($padstr, $pad).$token;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zapalenie Åojotokowe</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-157</link>
		<dc:creator>Zapalenie Åojotokowe</dc:creator>
		<pubDate>Fri, 27 Jun 2008 09:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-157</guid>
		<description>Seems my comment got cut off:

        // remove lines between an empty tag
        $xml = preg_replace("&#124;/ ] )(\s([^&#62;] ))?&#62;\n&#60;/\\1&#124;", "", $xml);</description>
		<content:encoded><![CDATA[<p>Seems my comment got cut off:</p>
<p>        // remove lines between an empty tag<br />
        $xml = preg_replace(&#8221;|/ ] )(\s([^>] ))?>\n</\\1|&#8221;, &#8220;&#8221;, $xml);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zapalenie Åojotokowe</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-156</link>
		<dc:creator>Zapalenie Åojotokowe</dc:creator>
		<pubDate>Fri, 27 Jun 2008 09:39:55 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-156</guid>
		<description>Doesn't work for empty tags like  - you need to remove the newline between them afterwards:

// add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries)
        $xml = preg_replace('/(&#62;)(&#60;)(\/*)/', "$1\n$2$3", $xml);

        // remove lines between an empty tag
        $xml = preg_replace("&#124;/ ] )(\s([^&#62;] ))?&#62;\n&#60;/\\1&#124;", "", $xml);</description>
		<content:encoded><![CDATA[<p>Doesn&#8217;t work for empty tags like  &#8211; you need to remove the newline between them afterwards:</p>
<p>// add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries)<br />
        $xml = preg_replace(&#8217;/(>)(< )(\/*)/&#8217;, &#8221;$1\n$2$3&#8221;, $xml);</p>
<p>        // remove lines between an empty tag<br />
        $xml = preg_replace(&#8221;|/ ] )(\s([^>] ))?>\n</\\1|&#8221;, &#8220;&#8221;, $xml);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Enrico</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-148</link>
		<dc:creator>Enrico</dc:creator>
		<pubDate>Mon, 19 May 2008 07:50:14 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-148</guid>
		<description>Nice stuff! Would be great to have tabs instead of spaces. Something like "formatXmlString($xml, $indent = "\t")".

Cheers
Enrico</description>
		<content:encoded><![CDATA[<p>Nice stuff! Would be great to have tabs instead of spaces. Something like &#8220;formatXmlString($xml, $indent = &#8221;\t&#8221;)&#8221;.</p>
<p>Cheers<br />
Enrico</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rolf</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-130</link>
		<dc:creator>Rolf</dc:creator>
		<pubDate>Sat, 16 Feb 2008 19:43:41 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-130</guid>
		<description>Very nice code here!</description>
		<content:encoded><![CDATA[<p>Very nice code here!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tomh</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-126</link>
		<dc:creator>tomh</dc:creator>
		<pubDate>Wed, 06 Feb 2008 09:40:35 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-126</guid>
		<description>Thanks! Exactlyl I was looking for.
Simple and powerful. Tom</description>
		<content:encoded><![CDATA[<p>Thanks! Exactlyl I was looking for.<br />
Simple and powerful. Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dave</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-121</link>
		<dc:creator>dave</dc:creator>
		<pubDate>Fri, 25 Jan 2008 16:37:44 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-121</guid>
		<description>Thanks for the feedback matt - unfortunately there's currently no way to selectively exclude tags from being formatted and indented... out of interest, what kind of tags did you have in mind? I could possibly put exceptions in if there was a need for them.</description>
		<content:encoded><![CDATA[<p>Thanks for the feedback matt &#8211; unfortunately there&#8217;s currently no way to selectively exclude tags from being formatted and indented&#8230; out of interest, what kind of tags did you have in mind? I could possibly put exceptions in if there was a need for them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-120</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Wed, 23 Jan 2008 15:49:37 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-120</guid>
		<description>Also, would there be a way to exclude certain tags such as  and  tags from creating a line break and formatting.</description>
		<content:encoded><![CDATA[<p>Also, would there be a way to exclude certain tags such as  and  tags from creating a line break and formatting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-119</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Wed, 23 Jan 2008 15:46:46 +0000</pubDate>
		<guid isPermaLink="false">http://recurser.com/articles/2007/04/05/format-xml-with-php/#comment-119</guid>
		<description>Hi, 

I just wanted to say that that is a fantastic bit of code. Great stuff</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>I just wanted to say that that is a fantastic bit of code. Great stuff</p>
]]></content:encoded>
	</item>
</channel>
</rss>
