Full-stack JavaScript path (23) DOM2 and DOM3, involving XML namespace extension (1), dom2dom3

Source: Internet
Author: User

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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.