note 92004 added to ref.simplexml

From: Date: Sat, 04 Jul 2009 16:38:04 +0000
Subject: note 92004 added to ref.simplexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-157918@lists.php.net to get a copy of this message
<?php function xml2Tree( SimpleXMLElement $xml, $root = "/" ) { $nodes = $xml->xpath($root.'*'); foreach( $nodes as $node ) { $arr[] = array( 'tag' => $node->getName(), 'attributes' => current( $node->attributes() ), 'value' => xml2Tree( $node, null ) ); } return ( empty( $arr ) ) ? (string) $xml : $arr; } $xml = '<root id="42"> <simple multi="yes" keep="yes"> String is kept as value </simple> <!-- Comments are lost --> <complex keep="yes"> This string is lost <simple keep="yes"/> </complex> </root>'; $xml = simplexml_load_string( $xml ); print_r( xml2Tree( $xml ) ); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 79.239.216.179 ---- Manual Page -- http://www.php.net/manual/en/ref.simplexml.php Edit -- https://master.php.net/note/edit/92004 Del: integrated -- https://master.php.net/note/delete/92004/integrated Del: useless -- https://master.php.net/note/delete/92004/useless Del: bad code -- https://master.php.net/note/delete/92004/bad+code Del: spam -- https://master.php.net/note/delete/92004/spam Del: non-english -- https://master.php.net/note/delete/92004/non-english Del: in docs -- https://master.php.net/note/delete/92004/in+docs Del: other reasons-- https://master.php.net/note/delete/92004 Reject -- https://master.php.net/note/reject/92004 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157918) next »