note 80855 added to ref.simplexml

From: Date: Mon, 04 Feb 2008 12:38:34 +0000
Subject: note 80855 added to ref.simplexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-135758@lists.php.net to get a copy of this message
As was said before don't use var_dump() or print_r() to see SimpleXML object structure as they do not returns always what you expect. Consider the following: <?php // data in xml $xml_txt = ' <root> <folder ID="65" active="1" permission="1"><![CDATA[aaaa]]></folder> <folder ID="65" active="1" permission="1"><![CDATA[bbbb]]></folder> </root>'; // load xml into SimpleXML object $xml = simplexml_load_string($xml_txt, 'SimpleXMLElement', LIBXML_NOCDATA);//LIBXML_NOCDATA LIBXML_NOWARNING // see object structure print_r($xml); /* this prints SimpleXMLElement Object ( [folder] => Array ( [0] => aaaa [1] => bbbb ) ) */ // but... foreach ($xml->folder as $value){ print_r($value); } /* prints complete structure of each folder element: SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 65 [active] => 1 [permission] => 1 ) [0] => aaaa ) SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 65 [active] => 1 [permission] => 1 ) [0] => bbbb ) */ ?> ---- Server IP: 193.198.184.18 Probable Submitter: 161.53.12.135 ---- Manual Page -- http://www.php.net/manual/en/ref.simplexml.php Edit -- https://master.php.net/note/edit/80855 Del: integrated -- https://master.php.net/note/delete/80855/integrated Del: useless -- https://master.php.net/note/delete/80855/useless Del: bad code -- https://master.php.net/note/delete/80855/bad+code Del: spam -- https://master.php.net/note/delete/80855/spam Del: non-english -- https://master.php.net/note/delete/80855/non-english Del: in docs -- https://master.php.net/note/delete/80855/in+docs Del: other reasons-- https://master.php.net/note/delete/80855 Reject -- https://master.php.net/note/reject/80855 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135758) next »