note 88305 deleted from function.simplexml-element-addChild by danbrown
| From: | danbrown@php.net | Date: | Mon, 19 Jan 2009 22:47:41 +0000 |
| Subject: | note 88305 deleted from function.simplexml-element-addChild by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149486@lists.php.net to get a copy of this message | ||
Note Submitter: name at example dot invalid
----
You don't really need addChild, you can directly add the element as you would with an array:
<?php
$string= '<movie><document example="true" /></movie>';
$XML = New SimpleXMLElement($string);
unset($XML->document);
$XML["country"]="USA";
$XML->title = "TheMovie";
$XML->title["status"]="Provisional";
$XML->actors->JohnSmith["status"]="Deceased";
print $XML->AsXML();
?>
Outputs:
<?xml version="1.0"?>
<movie country="USA"><title
status="Provisional">TheMovie</title><actors><JohnSmith
status="Deceased"/></actors></movie>
Now it would be great if you could make SimpleXML format the result better, like add newlines and
indent. And a way to reorder elements would be useful for SVG, where the order does matter.