Re: Problem with reading XML_Tree structure into array
| From: | Tomas V.V.Cox | Date: | Fri, 22 Mar 2002 02:10:26 +0000 |
| Subject: | Re: Problem with reading XML_Tree structure into array | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-1026@lists.php.net to get a copy of this message | ||
Markus Wolff wrote:
>
> 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();
$xmltree = $tree->getTreeFromFile();
> $conf = xml2array($conf);
$conf = xml2array($xmltree);
> </code>
Try the changes above :-)
Tomas V.V.Cox