/** * xml2Array * * parses DOM XML into an associative array * * @since version 1.8.0 * @access public */ function xml2Array($node, $attributes = false) { $return = array(); //loop over child nodes foreach ($node->childNodes as $node_child) { //does this child node have children? if ($node_child->hasChildNodes()) { //yes! child node has children //is this a collection of likely named nodes? if ($node->firstChild->nodeName == $node->lastChild->nodeName && $node->childNodes->length > 1) { //yes. add parsed xml as an element of the child node array $return[$node_child->nodeName][] = DJB::xml2array($node_child); } else { //no, the child nodes are named differently $return[$node_child->nodeName] = DJB::xml2array($node_child); } //end else } else { //no children. This is a leaf $return = $node_child->nodeValue; } //end else } //end foreach return $return; }