Prefers the serialized xmlns attribute and falls back to the DOM
namespaceURI, because the two diverge depending on how the element was
built and neither is reliable on its own:
Locally-built stanzas ($iq, stx, Builder) are created with
createElement and carry their namespace only in the xmlns attribute;
their namespaceURI is null.
Stanzas received over the XEP-0114 component transport are built with
createElementNS and carry their namespace only on namespaceURI; the
redundant xmlns attribute is omitted.
WebSocket / BOSH stanzas parsed by DOMParser carry both, except on
child elements that inherit the default namespace without redeclaring it
(those have only namespaceURI).
Checking both is the transport-agnostic way to read an element's namespace.
Parameters
elem: Element
The element whose namespace is wanted.
Returns string
The namespace URI, or null if the element has none.
Return the XML namespace of an element.
Prefers the serialized
xmlnsattribute and falls back to the DOMnamespaceURI, because the two diverge depending on how the element was built and neither is reliable on its own:$iq,stx, Builder) are created withcreateElementand carry their namespace only in thexmlnsattribute; theirnamespaceURIis null.createElementNSand carry their namespace only onnamespaceURI; the redundantxmlnsattribute is omitted.DOMParsercarry both, except on child elements that inherit the default namespace without redeclaring it (those have onlynamespaceURI).Checking both is the transport-agnostic way to read an element's namespace.