<?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>Nicola Moretti - Hanicker IT Blog &#187; xml</title>
	<atom:link href="http://blog.nicolamoretti.com/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nicolamoretti.com</link>
	<description>Tecnologia e Digital Hacks</description>
	<lastBuildDate>Thu, 12 Aug 2010 22:51:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Formattazione Output XML con PHP</title>
		<link>http://blog.nicolamoretti.com/2010/01/formattazione-output-xml-con-php/</link>
		<comments>http://blog.nicolamoretti.com/2010/01/formattazione-output-xml-con-php/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 09:12:12 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.nicolamoretti.com/?p=97</guid>
		<description><![CDATA[<br/>Funzione molto utile per formattare il testo XML in uscita (ad esempio da DomDocument). function formatXmlString($xml, $indentBase = 0, $indentString = ' ') { // 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); // now indent the tags $token = strtok($xml, "\n"); $result = [...]]]></description>
			<content:encoded><![CDATA[<br/><p>Funzione molto utile per formattare il testo XML in uscita (ad esempio da DomDocument).</p>
<pre name="code" class="php">
function formatXmlString($xml, $indentBase = 0, $indentString = ' ') {
// add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries)
$xml = preg_replace('/(&gt;)(&lt;)(\/*)/', "$1\n$2$3", $xml);
// now indent the tags
$token = strtok($xml, "\n");
$result = ''; // holds formatted version as it is built
$pad = ($indentBase &gt; 0) ? $indentBase : 0; // initial indent
$matches = array(); // returns from preg_matches()
// scan each line and adjust indent based on opening/closing tags
while ($token !== false):
// test for the various tag states
// 1. open and closing tags on same line - no change
if (preg_match('/.+&lt;\/\w[^&gt;]*&gt;$/', $token, $matches)):
$indent = 0;
// 2. closing tag - outdent now
elseif (preg_match('/^&lt;\/\w/', $token, $matches)):
$pad--;
// 3. opening tag - don't pad this one, only subsequent tags
elseif (preg_match('/^&lt;\w[^&gt;]*[^\/]&gt;.*$/', $token, $matches)):
$indent = 1;
// 4. no indentation needed
else:
$indent = 0;
endif;
// pad the line with the required number of leading spaces
$line = str_pad($token, strlen($token) + $pad, $indentString, STR_PAD_LEFT);
$result .= $line . "\n"; // add to the cumulative result, with linefeed
$token = strtok("\n"); // get the next token
$pad += $indent; // update the pad size for subsequent lines
endwhile;
return $result;
}
</pre>
<p>Tratta (e modificata) da <a href="http://recurser.com/articles/2007/04/05/format-xml-with-php/" >recurser.com</a>.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 601px; width: 1px; height: 1px;">http://recurser.com/articles/2007/04/05/format-xml-with-php/</div>
<p><a href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Google Reader" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a> <a href="http://www.addtoany.com/add_to/orkut?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Orkut" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/orkut.png" width="16" height="16" alt="Orkut"/></a> <a href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a> <a href="http://www.addtoany.com/add_to/myspace?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="MySpace" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/myspace.png" width="16" height="16" alt="MySpace"/></a> <a href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a> <a href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a> <a href="http://www.addtoany.com/add_to/yahoo_bookmarks?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Yahoo Bookmarks" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/yahoo.png" width="16" height="16" alt="Yahoo Bookmarks"/></a> <a href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a> <a href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a> <a href="http://www.addtoany.com/add_to/netlog?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Netlog" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/netlog.png" width="16" height="16" alt="Netlog"/></a> <a href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Tumblr" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a> <a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fblog.nicolamoretti.com%2F2010%2F01%2Fformattazione-output-xml-con-php%2F&amp;linkname=Formattazione%20Output%20XML%20con%20PHP" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.nicolamoretti.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.nicolamoretti.com/2010/01/formattazione-output-xml-con-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
