protected static function DOMNodeValue(DOMNode $node, $associative = false, $attributes = false)
    {
        // Return the value immediately when we're dealing with a leaf
        // node without attributes or we simply don't want them included
        if (static::DOMNodeChildCount($node) == 0 && ($node->hasAttributes() === false || $attributes === false)) {
            return $node->nodeValue;
        }

        $children = array();

        if ($node->hasAttributes() && $attributes) {
            $children['@'] = static::DOMNodeAttributes($node);
        }

        foreach ($node->childNodes as $child) {
            // Skip text nodes containing whitespace
            if ($child instanceof DOMText && $child->isWhitespaceInElementContent()) {
                continue;
            }

            if (static::DOMNodeChildCount($child) > 0) {
                $value = static::DOMNodeValue($child, $associative);
            } else {
                $value = $child->nodeValue;
            }

            if ($associative) {
                $children[$child->nodeName][] = $value;
            } else {
                $children[] = $value;
            }
        }

        return $children;
    }