Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

IsDefaultNamespace

The following is a snippet to get isDefaultNamespace() supported across other browsers.

Note that all Gecko-based browsers (including Firefox) support Node.isDefaultNamespace. This function is not necessary for Gecko-based browsers (though the function will quickly return the standard value for Mozilla browsers).
// https://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-isDefaultNamespace
// https://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#isDefaultNamespaceAlgo

function isDefaultNamespace(node, namespaceURI) {
    if (node.isDefaultNamespace) {
        return node.isDefaultNamespace(namespaceURI);
    }
    switch (node.nodeType) {
        case 1: //  ELEMENT_NODE
            if (!node.prefix) {
                return (node.namespaceURI === namespaceURI);
            }
            if (node.attributes.length) {
                for (var i=0; i < node.attributes.length; i++) {
                    var att = node.attributes[i];
                    if (att.localName === 'xmlns') {
                        return att.value === namespaceURI;
                    }
                }
            }
            if (node.parentNode) {
            // EntityReferences may have to be skipped to get to it
                return isDefaultNamespace(node.parentNode, namespaceURI);
            }
            else {
                return false; // unknown;
            }
        case 9: // DOCUMENT_NODE
            return isDefaultNamespace(node.documentElement, namespaceURI);
        case 6: // ENTITY_NODE
        case 12: // NOTATION_NODE
        case 10: // DOCUMENT_TYPE_NODE
        case 11: // DOCUMENT_FRAGMENT_NODE
            return false; // unknown
        case 2: // ATTRIBUTE_NODE:
            if (node.ownerElement ) {
                return isDefaultNamespace(node.ownerElement , namespaceURI);
            }
            else {
                return false; // unknown
            }
        default:
            if (node.parentNode) {
            // EntityReferences may have to be skipped to get to it
                return isDefaultNamespace(node.parentNode, namespaceURI);
            }
            else {
                return false; // unknown
            }
    }
}

 

Document Tags and Contributors

 Contributors to this page: wbamberg, Brettz9
 Last updated by: wbamberg,