private static function DOMtoArray($node)
    {
        $occurence = array();
        $result = null;

        if ($node->childNodes) {
            foreach ($node->childNodes as $child) {
                if (isset($occurence[$child->nodeName])) {
                    $occurence[$child->nodeName]++;
                } else {
                    $occurence[$child->nodeName] = 1;
                }
            }
        }

        if ($node->nodeType == XML_TEXT_NODE || $node->nodeType == XML_CDATA_SECTION_NODE) {
            $result = html_entity_decode(
                htmlentities(
                    (string) $node->nodeValue,
                    ENT_COMPAT,
                    'UTF-8'
                ),
                ENT_COMPAT,
                'ISO-8859-15'
            );
        } else {
            if ($node->hasChildNodes()) {
                $children = $node->childNodes;

                for ($i=0; $i<$children->length; $i++) {
                    $child = $children->item($i);

                    switch ($child->nodeName) {
                        case '#cdata-section':
                        case '#text':
                            $text = static::DOMtoArray($child);

                            if (trim($text) != '') {
                                $result[self::VALUE] = static::DOMtoArray($child);
                            };
                            break;

                        default:
                            if ($occurence[$child->nodeName] > 1) {
                                $result[$child->nodeName][] = static::DOMtoArray($child);
                            } else {
                                $result[$child->nodeName] = static::DOMtoArray($child);
                            }
                    }
                }
            }

            if ($node->hasAttributes()) {
                $attributes = $node->attributes;

                if (!is_null($attributes)) {
                    foreach ($attributes as $key => $attr) {
                        $result[self::ATTRIBUTES][$attr->name] = $attr->value;
                    }
                }
            }
        }

        return $result;
    }