"Barring polygamy, you will break up with every person you date minus one." - Yellow
Question #45263 posted on 05/26/2008 3:01 a.m.

Dear PHP Paragon,

I am currently learning how to use php5 to manipulate and display xml. I have been using simplexml as it has boasts almost no learning curve. The supported functions allow 'addChild', but there is nothing to 'removeChild'. Is there a solution? perhaps using PHP XML DOM?

"This will be wildly useful, I promise"

A: Dear be,

This article: Parsing XML using SimpleXML says that a non-ideal way to force SimpleXML to trash an element is to set it to null:
$sitemap->url[0] = null;

He also explains why that's not a very good idea.

I would recommend biting the bullet and diving into XML DOM, it's rather handy. You can find a lot of great information on the subject over at http://w3schools.com/dom/default.asp. It's not as bad as you think, especially if you already understand how XML is structured.

-Curious Physics Minor