PayPal\Core\PPUtils::xmlNodeToArray PHP Method

xmlNodeToArray() private static method

Convert a DOM node to an intermediate nested array representation that can be iterated
private static xmlNodeToArray ( DOMNode $node )
$node DOMNode DOM node to convert
    private static function xmlNodeToArray($node)
    {
        $result = array();
        $children = $node->childNodes;
        if (!empty($children)) {
            for ($i = 0; $i < (int) $children->length; $i++) {
                $child = $children->item($i);
                if ($child !== null) {
                    if ($child->childNodes->item(0) instanceof \DOMText) {
                        $result[$i]['name'] = $child->nodeName;
                        $result[$i]['text'] = $child->childNodes->item(0)->nodeValue;
                        if ($child->hasAttributes()) {
                            foreach ($child->attributes as $k => $v) {
                                if ($v->namespaceURI != 'http://www.w3.org/2001/XMLSchema-instance') {
                                    $result[$i]['attributes'][$v->name] = $v->value;
                                }
                            }
                        }
                    } else {
                        if (!in_array($child->nodeName, $result)) {
                            $result[$i]['name'] = $child->nodeName;
                            $result[$i]['children'] = PPUtils::xmlNodeToArray($child);
                            if ($child->hasAttributes()) {
                                $attrs = $child->attributes;
                                foreach ($attrs as $k => $v) {
                                    if ($v->namespaceURI != 'http://www.w3.org/2001/XMLSchema-instance') {
                                        $result[$i]['attributes'][$v->name] = $v->value;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return $result;
    }