note 12601 deleted from function.xml-parse-into-struct by sniper
| From: | sniper@php.net | Date: | Fri, 05 Dec 2003 00:32:23 +0000 |
| Subject: | note 12601 deleted from function.xml-parse-into-struct by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-61423@lists.php.net to get a copy of this message | ||
Note Submitter: mh@mainlab.de
----
I use the following function to access data in arrays produced by xml_parse_into_struct:
$data must be the beginning of the name of the arrays which is followed by "_index" and
"_vals" to complete both names.
$location tells the function which value to return. If you have XML like:
"<para><note>simple note</note></para>" my function will return
"simple note" if you pass "NOTE/PARA" as $location. I hope this helps anybody!!
Here is the code:
function get_xml_values ($data, $location) {
// analyses set of arrays ($data) containing XML-data (generated by parse_xml_data)
// Returned value: XML-value corresponding to search pattern specified in $location
$_index = $data . "_index";
$_vals = $data . "_vals";
global $$_index, $$_vals;
$index = array();
$vals = array();
$index = $$_index;
$vals = $$_vals;
$location = explode("/", $location);
$location_level = count($location);
//initializing open/close values
$open = 0;
$close = 999999999;
$value = "";
for ($n=0; $n<$location_level; $n++) {
for ($i=0; $i<count($index[$location[$n]]); $i++) {
$idx = $index[$location[$n]][$i];
$type = $vals[$idx]["type"];
If ($type == "open" AND $idx >= $open) {
$open = $idx;
}
If ($type == "close" AND $idx <= $close) {
$close = $idx;
break;
}
If ($type == "complete") {
$value = $vals[$idx]["value"];
break;
}
}
If ($value != "") {
break;
}
}
return $value;
}