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

Content with Style:
Remove nodes in SimpleXMLElement
Jul 16, 2009 @ 16:15:57

The Content with Style blog has this quick tip on removing nodes from inside of a SimpleXML object without causing problems with its internal handling.

You might think otherwise and hack it with unset(), as it was done in one of the web applications I inherited at work, but today I found out that this works under some conditions, but not with every setup. I'd love to tell you what exactly the differences are that make it break, but I didn't spend the time tracking it down.

Instead, he suggests a call to dom_import_simplexml to swap the object over to the DOM, performing a removeChild on the node and pushing it back over to SimpleXML if the need's there.

tagged: removechild dom tutorial simplexml

Link:

DevShed:
Parsing Child Nodes with the DOM XML extension in PHP 5
Apr 08, 2008 @ 14:47:48

Alejandro Gervasio has finished up his series on DevShed looking at working with the DOM extension in PHP5 with this new article, a look at parsing child nodes.

In this last chapter of the series, I'm going to teach you how to handle the child nodes of an XML document by way of two simple methods, called hasChildNode() and removeChild() respectively. So let's not waste any more time in preliminaries and learn how to use them in a helpful way.

They review some of the concepts mentioned previously before moving ahead to the use of the hasChildNodes and removeChild methods to check for children and get rid of only certain ones.

tagged: dom xml php5 tutorial child node haschildnodes removechild

Link:


Trending Topics: