function BH_DOM_Node_lookupNamespaceURI(node, prefix) { // prefixes bound by definition to specific namespace names // this behavior might be non-compliant; for details please see // http://lists.w3.org/Archives/Public/www-dom/2005OctDec/0116 if (prefix == 'xml') return 'http://www.w3.org/XML/1998/namespace'; if (prefix == 'xmlns') return 'http://www.w3.org/2000/xmlns/'; // more lookup is not possible without a node if (!node) return null; // treat empty string as null if (prefix == "") prefix = null; if (node.nodeType == 9) // DOCUMENT_NODE return arguments.callee(node.documentElement, prefix); if (node.nodeType == 6) // ENTITY_NODE return null; if (node.nodeType == 12) // NOTATION_NODE return null; if (node.nodeType == 10) // DOCUMENT_TYPE_NODE return null; if (node.nodeType == 11) // DOCUMENT_FRAGMENT_NODE return null; if (node.nodeType == 2) // ATTRIBUTE_NODE return arguments.callee(node.ownerElement, prefix); if (node.nodeType != 1) // ELEMENT_NODE { for (var cur = node.parentNode; cur; cur = cur.parentNode) { if (cur.nodeType != 1) // ELEMENT_NODE continue; // lookupNamespaceURI of ancestor element return arguments.callee(cur, prefix); } return null; } // // for elements // if (node.namespaceURI != null && node.prefix == prefix) { // Note: prefix could be "null" in this case we are // looking for the default namespace return node.namespaceURI; } var attrs = node.attributes; // for all attributes... this should filter out invalid namespace // declarations, but this isn't 100% certain as yet; also, there // are some problems with the relevant specs... for (var i = 0; i < attrs.length; ++i) { var attr = attrs.item(i); // not a namespace declaration if (attr.namespaceURI != 'http://www.w3.org/2000/xmlns/') continue; // non default namespace if (attr.prefix == "xmlns" && attr.localName == prefix) { // if (attr.value == "") return null; // if this is true the xml namespace was bound to a // different prefix which is not allowed if (attr.value == 'http://www.w3.org/XML/1998/namespace') return null; // if this is true the xmlns namespace was bound to // a different prefix which is not allowed if (attr.value == 'http://www.w3.org/2000/xmlns/') return null; return attr.value; } if (attr.localName == "xmlns" && prefix == null) { // if (attr.value == "") return null; // assume xmlns='http://www.w3.org/XML/1998/namespace' is allowed // http://lists.w3.org/Archives/Public/xml-names-editor/2005Dec/0001 // should have a response if they are not if (attr.value == 'http://www.w3.org/XML/1998/namespace') return attr.value; // assume xmlns='http://www.w3.org/2000/xmlns/' is allowed, cf above if (attr.value == 'http://www.w3.org/2000/xmlns/') return attr.value; return attr.value; } for (var cur = node.parentNode; cur; cur = cur.parentNode) { if (cur.nodeType != 1) // ELEMENT_NODE continue; // lookupNamespaceURI of ancestor element return arguments.callee(cur, prefix); } } return null; }