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

From: Date: Fri, 09 Aug 2002 05:20:49 +0000
Subject: note 24199 added to function.xml-parse-into-struct
Groups: php.notes 
Request: Send a blank email to php-notes+get-34593@lists.php.net to get a copy of this message
This is based on a comment above by mh@mainlab.de. This version makes more sense to me and I included a few comments that might make it more usefull for specific purposes. // Look through $vals and $index, // generated by parse_xml_data(), // for $location. $location resembles a unix path. // E.g. "my/xml/path/to/my/data". // Note: This is NOT a full-feature xml utility. // Your path must be unique in the xml data // and the tags must not contain slashes. // // returns: cdata from last element of $location // or NULL. function get_xml_values($vals, $index, $location) { $location = explode('/', $location); $location_level = count($location); for ($n=0; $n<$location_level; ++$n) { $val_indexes=$index[$location[$n]]; $good=0; for ($i=0; $i<count($val_indexes); ++$i) { $v = $vals[$val_indexes[$i]]; // level is 1 based, n is 0 based: if ($v['level']-1 == $n) { if ($v['type'] == 'open') { // We found an open tag at the correct level. $good=1; break; // Remove break to avoid 'open' hiding // 'complete' at last $n. (Speed Vs. Robustness: // For now, I'm going with speed). } if ($v['type'] == 'complete') { // We found it, after finding all the prior elements: // You may want to change this to // return $v // so you can call $v['value'] and $v['attributes'] return $v['value']; } } } if (!$good) { return NULL; } } } -- http://www.php.net/manual/en/function.xml-parse-into-struct.php http://master.php.net/manage/user-notes.php?action=edit+24199 http://master.php.net/manage/user-notes.php?action=delete+24199 http://master.php.net/manage/user-notes.php?action=reject+24199

« previous php.notes (#34593) next »