note 45372 added to function.xml-parse-into-struct

From: Date: Fri, 03 Sep 2004 16:21:26 +0000
Subject: note 45372 added to function.xml-parse-into-struct
Groups: php.notes 
Request: Send a blank email to php-notes+get-75992@lists.php.net to get a copy of this message
I wrote this function in a bad mood, to get some data you can loop through. sprint_r or var_dump its output to see what it does. It's not pretty, but at least you can loop through the data without a LOT of hassle. This can also be done with handlers, but I couldn't be bothered with global variables. <?php $data = xml_parse_into_struct($somexml); function xml_getmeaningfuldata($data) { foreach($data as $element) { if ($element['type'] == "open") { if (!$elementnos[$parents.$element['tag']]) { $elementnos[$parents.$element['tag']] = 1; } $elements[$parents.$element['tag'].":". $elementnos[$parents.$element['tag']]]['attributes'] = $element['attributes']; $elements[$parents.$element['tag'].":". $elementnos[$parents.$element['tag']]]['value'] = trim($element['value']); $parents .= $element['tag'].":".$elementnos[$parents.$element['tag']]."^"; } if ($element['type'] == "cdata") { if (trim($element['value'])) { $elements[$parents.$element['tag'].":". $elementnos[$parents.$element['tag']]]['values'] = $element['value']; } } if ($element['type'] == "complete") { if (!$elementnos[$parents.$element['tag']]) { $elementnos[$parents.$element['tag']] = 1; } $elements[$parents.$element['tag'].":". $elementnos[$parents.$element['tag']]]['attributes'] = $element['attributes']; $elements[$parents.$element['tag'].":". $elementnos[$parents.$element['tag']]]['value'] = trim($element['value']); $elementnos[$parents.$element['tag']]++; } if ($element['type'] == "close") { $parents = substr($parents, 0, strrpos(substr($parents, 0, -1), "^")+1); $elementnos[$parents.$element['tag']]++; // if (sizeof($parents) == 1) unset($parents); } } return $elements; } ---- Manual Page -- http://www.php.net/manual/en/function.xml-parse-into-struct.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45372 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45372&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45372&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#75992) next »