Problem with reading XML_Tree structure into array

From: Date: Thu, 21 Mar 2002 23:43:16 +0000
Subject: Problem with reading XML_Tree structure into array
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-1024@lists.php.net to get a copy of this message
Hi PEAR folks, I´ve just discovered the class XML_Tree in CVS and couldn´t resist to give it a try ;-) Currently I´m trying to read a very simple XML file and convert its structure to an equally simple array. Here´s the code I wrote to achieve that: <code> require_once("XML/Tree.php"); function xml2array(&$tree) { $config = array(); foreach($tree->root->children as $rootChild) { foreach($rootChild->children as $subChild) { $config[$rootChild->name][$subChild->name] = $subChild->content; } } return $config; } $tree = new XML_Tree("grid_settings.xml"); $tree->getTreeFromFile(); $conf = xml2array($conf); </code> Making extensive use of print_r(), I´ve found out that the tree structure is being built correctly from the XML file so after getTreeFromFile(), $tree contains a property called root, which itself has a property called children which is an array of node objects. So far so good, but why, why in the world does the first call to foreach() in my function throw this error: > Warning: Invalid argument supplied for foreach() in > c:\inetpub\wwwroot\grid\xmltest2.php on line 9 As a result, the returned array is empty. Am I blind or something? What did I miss? Regards, Markus P.S.: Tried this using PHP4.1.0 on IIS and latest versions of XML/Tree.php and XML/Tree/Node.php from CVS. -- *21st Media* | Consulting, Konzeption, Produktion für die Bereiche: Markus Wolff | Internet, Intranet, eCommerce, Content Management, Hamburg,Germany | Softwareentwicklung, 3D-Animation, Videostreaming http://21st.de | Tel. [+49](0)40/6887949-0, Fax: [+49](0)40/6887949-1

« previous php.pear.general (#1024) next »