News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthew Turland's Blog:
Renaming a DOMNode in PHP
February 10, 2010 @ 09:16:58

Matthew Turland has a new post to his blog sharing a handy trick if you've ever looked for a way to use the DOM functionality on PHP to rename a certain node in an XML document. Since the node_name is read-only, some trickery is required.

A recent work assignment had me using PHP to pull HTML data into a DOMDocument instance and renaming some elements, such as b to strong or i to em. As it turns out, renaming elements using the DOM extension is rather tedious.

His method isn't so much of an update of what's already there as it is to replicate the attributes and child nodes of the node you're targeting and pus those back into the document with a call to replaceChild on the parent.

0 comments voice your opinion now!
rename dom xml node tutorial


blog comments powered by Disqus

Similar Posts

Matthew Weier O'Phinney's Blog: Rendering Zend_Form decorators individually

Felix Geisendörfer's Blog: Learning from the CakePHP Source Code (Part 1)

Greg Beaver's Blog: PhpDocumentor 1.3.0 stable is released

Zend Developer Zone: Building Dashboards With PHP and Flex

NETTUTS.com: The Problem with PHP’s Prepared Statements


Community Events





Don't see your event here?
Let us know!


voicesoftheelephpant community version security artisanfiles tool interview series opinion release library laravel composer introduction podcast list conference framework symfony language

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework