note 20059 added to function.xpath-eval
| From: | sbarnum at pointsystems dot chek dot com | Date: | Wed, 20 Mar 2002 23:33:11 +0000 |
| Subject: | note 20059 added to function.xpath-eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28013@lists.php.net to get a copy of this message | ||
This function has come in handy for recursively viewing the results of xpath searches. It iterates
through a node and converts it to a big associative array:
/**
* Recursive function to convert xml root node to big assoc array
*/
function xmlnode2array($node) {
if ($node->type==XML_ELEMENT_NODE) {
if ($attrArray = $node->attributes()) {
// parse attributes //
foreach($attrArray AS $attr) {
$out['ATTRIBUTE'][$attr->name] = $attr->value;
}
}
if ($childArray = $node->children()) {
// add child nodes //
foreach($childArray AS $child) {
if ($child->type==XML_ELEMENT_NODE) {
$out[$child->tagname][] = xmlnode2array($child);
} else {
if ($content = xmlnode2array($child))
$out['CONTENT'] = $content;
}
}
}
} else {
// this is a CONTENT NODE //
$out = trim($node->content);
if (!$out) return false;
}
return $out;
}
--
http://www.php.net/manual/en/function.xpath-eval.php
http://master.php.net/manage/user-notes.php?action=edit+20059
http://master.php.net/manage/user-notes.php?action=delete+20059
http://master.php.net/manage/user-notes.php?action=reject+20059