Full-stack JavaScript path (23) DOM2 and DOM3, involving XML namespace extension (1), dom2dom3
<!DOCTYPE html><xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml">
The preceding example shows how to use xmlns to specify a namespace and use xmlns: prefix to specify a prefix. Once a prefix is specified, it must be used for the current element and child element.
Sometimes, to avoid conflicts between different languages, you also need to use namespaces to limit features, as shown in the following example.
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:head><xhtml:title>Example XHTML page</xhtml:title></xhtml:head><xhtml:body xhtml:class="home">Hello world!</xhtml:body></xhtml:html>
(1) Node type changes:
In DOM2, the Node type includes the following namespace-specific features:
In DOM3, the following attributes and methods are further added:
(2) Document Type changes
CreateElementNS (namespaceURL, tagName)
CreateAttributeNS (namespaceURL, tagName)
GetElementByTagName (namespaceURL, tagName)
Only when there are two or more namespaces in the document, these namespaces are required.
(3) Element type changes
DOM core involves namespace changes, mainly the methods of operating features.
GetAttributeNS (namespaceURL, localName)
GetAttributeNodeNS (namespaceURL, localName)
GetElementByTagName (namespaceURL, tagName)
HasAttribute (namespaceURL, tagName) // The dom also adds hasAttribute ()
RemoveAttributeNS (namespaceURL, localName)
SetAttributeNS (namespaceURL, localName, value)
SetAttributeNodeNS (namespaceURL, attNode)
Except for the first parameter, these methods have the same effect as the related methods in DOM1; the first parameter is always a namespace URI.
(4) NamedNodeMap type changes
GetNamedItemNS (namespaceURL, localName)
SetNamedItemNS (node)
RemoveNamedItemNS (namespaceURL, localName)
These methods are rarely used because they are generally accessed by elements.