note 88305 added to function.simplexml-element-addChild

From: Date: Mon, 19 Jan 2009 22:28:25 +0000
Subject: note 88305 added to function.simplexml-element-addChild
Groups: php.notes 
Request: Send a blank email to php-notes+get-149485@lists.php.net to get a copy of this message
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. ---- Server IP: 130.206.1.5 Probable Submitter: 79.157.57.133 ---- Manual Page -- http://www.php.net/manual/en/function.simplexml-element-addChild.php Edit -- https://master.php.net/note/edit/88305 Del: integrated -- https://master.php.net/note/delete/88305/integrated Del: useless -- https://master.php.net/note/delete/88305/useless Del: bad code -- https://master.php.net/note/delete/88305/bad+code Del: spam -- https://master.php.net/note/delete/88305/spam Del: non-english -- https://master.php.net/note/delete/88305/non-english Del: in docs -- https://master.php.net/note/delete/88305/in+docs Del: other reasons-- https://master.php.net/note/delete/88305 Reject -- https://master.php.net/note/reject/88305 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149485) next »