<?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: Mangling XML as Text with PHP DOM</title>
	<atom:link href="http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<pubDate>Mon, 01 Dec 2008 22:40:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: mkoenig</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-769637</link>
		<dc:creator>mkoenig</dc:creator>
		<pubDate>Mon, 28 Jul 2008 11:14:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-769637</guid>
		<description>I wish i would have read this post about a week earlier.</description>
		<content:encoded><![CDATA[<p>I wish i would have read this post about a week earlier.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew Turland</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-767112</link>
		<dc:creator>Matthew Turland</dc:creator>
		<pubDate>Thu, 24 Jul 2008 23:41:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-767112</guid>
		<description>1) http://us.php.net/manual/en/class.domnode.php#domnode.props.textcontent

2) http://svn.assembla.com/svn/php_domquery/trunk/DomQuery.php</description>
		<content:encoded><![CDATA[<p>1) <a href="http://us.php.net/manual/en/class.domnode.php#domnode.props.textcontent" rel="nofollow">http://us.php.net/manual/en/class.domnode.php#domnode.props.textcontent</a></p>
<p>2) <a href="http://svn.assembla.com/svn/php_domquery/trunk/DomQuery.php" rel="nofollow">http://svn.assembla.com/svn/php_domquery/trunk/DomQuery.php</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: AppSol</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-766966</link>
		<dc:creator>AppSol</dc:creator>
		<pubDate>Thu, 24 Jul 2008 20:16:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-766966</guid>
		<description>&lt;blockquote&gt;Unfortunately there doesn’t seem to be a way with PHP DOM to get the text equivalent of any arbitrary node&lt;/blockquote&gt;

Ummmh, Xpath?

Seriously PHPs XSLT support in 5 is great, you can even call PHP functions from within the XSLT.</description>
		<content:encoded><![CDATA[<blockquote><p>Unfortunately there doesn’t seem to be a way with PHP DOM to get the text equivalent of any arbitrary node</p></blockquote>
<p>Ummmh, Xpath?</p>
<p>Seriously PHPs XSLT support in 5 is great, you can even call PHP functions from within the XSLT.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: David Sklar</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-766784</link>
		<dc:creator>David Sklar</dc:creator>
		<pubDate>Thu, 24 Jul 2008 15:18:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-766784</guid>
		<description>(Ugh. Looks like the "code block" choice in the editor here doesn't preserve newlines.)</description>
		<content:encoded><![CDATA[<p>(Ugh. Looks like the &#8220;code block&#8221; choice in the editor here doesn&#8217;t preserve newlines.)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: David Sklar</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-766783</link>
		<dc:creator>David Sklar</dc:creator>
		<pubDate>Thu, 24 Jul 2008 15:17:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-766783</guid>
		<description>I love regular expressions as much (more than?) the next guy, but it seems uncomfortably brittle to use them to "parse" XML. If XSLT is overkill for this sort of XML transformation, why not then instead use XPath to identify the nodes you want to change and a little bit of DOM manipulation to effect the change? E.g.:

&lt;code&gt;
$d = new DOMDocument($xml);
$d-&#62;loadXml($xml);
$x = new DOMXPath($d);

$replacements = array('//div[@class="section"]' =&#62; 'section',
                      '//code' =&#62; 'jstype');

foreach ($replacements as $query =&#62; $newName) {
    foreach ($x-&#62;query($query) as $oldNode) {
        $newNode = $oldNode-&#62;ownerDocument-&#62;createElement($newName);
        foreach ($oldNode-&#62;childNodes as $child) {
            $newNode-&#62;appendChild($child-&#62;cloneNode(true));
        }
        $oldNode-&#62;parentNode-&#62;replaceChild($newNode, $oldNode);
    }
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I love regular expressions as much (more than?) the next guy, but it seems uncomfortably brittle to use them to &#8220;parse&#8221; XML. If XSLT is overkill for this sort of XML transformation, why not then instead use XPath to identify the nodes you want to change and a little bit of DOM manipulation to effect the change? E.g.:</p>
<code>
$d = new DOMDocument($xml);
$d-&gt;loadXml($xml);
$x = new DOMXPath($d);

$replacements = array('//div[@class="section"]' =&gt; 'section',
                      '//code' =&gt; 'jstype');

foreach ($replacements as $query =&gt; $newName) {
    foreach ($x-&gt;query($query) as $oldNode) {
        $newNode = $oldNode-&gt;ownerDocument-&gt;createElement($newName);
        foreach ($oldNode-&gt;childNodes as $child) {
            $newNode-&gt;appendChild($child-&gt;cloneNode(true));
        }
        $oldNode-&gt;parentNode-&gt;replaceChild($newNode, $oldNode);
    }
}
</code>]]></content:encoded>
	</item>
	<item>
		<title>By: hmm</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-766760</link>
		<dc:creator>hmm</dc:creator>
		<pubDate>Thu, 24 Jul 2008 13:56:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-766760</guid>
		<description>I just want paste a small "review" about your article, which I found on other blog ( http://blog.wombert.de/post/43374548/sitepoint-blogs-mangling-xml-as-text-with-php-dom ).

"say that this article is the top contestant for the biggest fail of the year… he uses ereg functions (they always sucked, and will be gone in PHP6), parses and replaces XML by hand, has apparently never heard of XPath and most of all… XSL was designed to do all this, like… decades ago, but hey, it’s only 2008…"

I agree in 100% with this opinion.</description>
		<content:encoded><![CDATA[<p>I just want paste a small &#8220;review&#8221; about your article, which I found on other blog ( <a href="http://blog.wombert.de/post/43374548/sitepoint-blogs-mangling-xml-as-text-with-php-dom" rel="nofollow">http://blog.wombert.de/post/43374548/sitepoint-blogs-mangling-xml-as-text-with-php-dom</a> ).</p>
<p>&#8220;say that this article is the top contestant for the biggest fail of the year… he uses ereg functions (they always sucked, and will be gone in PHP6), parses and replaces XML by hand, has apparently never heard of XPath and most of all… XSL was designed to do all this, like… decades ago, but hey, it’s only 2008…&#8221;</p>
<p>I agree in 100% with this opinion.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: fte</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-766743</link>
		<dc:creator>fte</dc:creator>
		<pubDate>Thu, 24 Jul 2008 13:27:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-766743</guid>
		<description>What was the reason to do not use XSLT ?</description>
		<content:encoded><![CDATA[<p>What was the reason to do not use XSLT ?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-766695</link>
		<dc:creator>Gabriel</dc:creator>
		<pubDate>Thu, 24 Jul 2008 12:12:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-766695</guid>
		<description>Hi!

Seems to be the perfect use case for XSLT instead of PHP and DOM. Any reason why you chose PHP?

Gabriel</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>Seems to be the perfect use case for XSLT instead of PHP and DOM. Any reason why you chose PHP?</p>
<p>Gabriel</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Marklar</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-766684</link>
		<dc:creator>Marklar</dc:creator>
		<pubDate>Thu, 24 Jul 2008 11:44:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-766684</guid>
		<description>Are you some sort of idiot?

Have you ever heard of XSL? Are you even aware of the fact that ereg() is deprecated?

Seriously, WTF?</description>
		<content:encoded><![CDATA[<p>Are you some sort of idiot?</p>
<p>Have you ever heard of XSL? Are you even aware of the fact that ereg() is deprecated?</p>
<p>Seriously, WTF?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan Reynolds</title>
		<link>http://www.sitepoint.com/blogs/2008/07/24/mangling-xml-as-text-with-php-dom/#comment-766613</link>
		<dc:creator>Nathan Reynolds</dc:creator>
		<pubDate>Thu, 24 Jul 2008 09:52:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2703#comment-766613</guid>
		<description>Should be able to use &lt;code&gt;$xmltext = $xmldom-&#62;documentElement-&#62;saveXML($node);&lt;/code&gt;.

Now why that's a document method rather than a node method, I've no idea.</description>
		<content:encoded><![CDATA[<p>Should be able to use <code>$xmltext = $xmldom-&gt;documentElement-&gt;saveXML($node);</code>.</p>
<p>Now why that&#8217;s a document method rather than a node method, I&#8217;ve no idea.</p>]]></content:encoded>
	</item>
</channel>
</rss>
