JavaScript node operations and DOMDocument attributes and method_javascript skills

Source: Internet
Author: User
Tags cdata
Recently, it was found that the DOMDocument object is very important, and XMLHTTP is also very important. The case must not be wrong. attribute:
1 Attributes storage node attribute list (read-only)
2. List of child nodes of the childNodes storage node (read-only)
3 dataType return the Data Type of this node
4 Definition defines nodes in DTD or XML mode (read-only)
5. Doctype specifies the file type node (read-only)
6. documentElement: return the root element of the document (readable and writable)
7. firstChild: returns the first subnode of the current node (read-only)
8 Implementation: returned XMLDOMImplementation object
9 lastChild returns the last child node of the current node (read-only)
10 nextSibling returns the next sibling node of the current node (read-only)
11 nodeName: return the node name (read-only)
12 nodeType return node type (read-only)
13 nodeTypedValue storage node value (read/write)
14 nodeValue: return the node text (read/write)
15 ownerDocument: returns the root document containing this node (read-only)
16 parentNode returns the parent node (read-only)
17. Parsed: returns whether the node and Its subnodes have been Parsed (read-only)
18 Prefix returns the namespace Prefix (read-only)
19 preserveWhiteSpace specifies whether to retain white space (read/write)
20 previussibling returns the previous sibling node of this node (read-only)
21 Text returns the Text content of this node and its descendants (read/write)
22url returns the URL of the recently loaded XML document (read-only)
23Xml returns the XML Representation of the node and its descendants (read-only)
Method:
1 appendChild adds a new subnode to the current node, which is placed after the last subnode
2 cloneNode: returns the copy of the current node.
3 createAttribute create new attribute
4. createCDATASection: Create a CDATA segment containing the given data
5 createComment create a comment Node
6 createDocumentFragment create a DocumentFragment object
7 createElement create an element node
8 createEntityReference: Create an EntityReference object
9 createNode create nodes of the given type, name, and namespace
10 createPorcessingInstruction
11 createTextNode: Create a text node that includes the given data
12 getElementsByTagName: returns the set of elements with the specified name.
13 hasChildNodes: returns whether the current node has subnodes.
14 insertBefore insert a subnode before a specified Node
15 Load import the XML document at the specified position
16 loadXML import the XML document of the specified string
17 removeChild deletes the specified subnode from the subnode list
18 replaceChild Replace the specified subnode from the subnode list
19 Save the XML file to the specified Node
20 selectNodes: matches the specified node and returns the list of matched nodes.
21 selectSingleNode matches the specified node and returns the first matched node.
22. transformNode converts nodes and their descendants using the specified style table.
23 transformNodeToObject: Use the specified style sheet to convert nodes and their descendants to objects.
*********************************
DOM (Document Object Model)
The introduction of the DOM (Document Object Model) concept makes HTML even more powerful. However, some friends who are familiar with DHTML are still a bit difficult, just because the current manual is not very scientific and is written by letters.
In fact, the most important thing in DOM is to know the relationship between nodes (between node andnode). Do not read the DOM in DHTML from start to end.
Some attributes and methods do you have the "Unforgettable" skills of Zhang song during the Three Kingdoms? No, let me analyze it:
In fact, what DOM teaches us is a hierarchical structure. You can think of it as a tree structure, just like our directory. A root directory contains sub-directories and sub-directories.
Directory ......
Root Node:
DOM calls every object in the hierarchy a NODE. Take HTML hypertext markup language as an example: a root of the entire document is, Which can be used in DOM
Document.doc umentElement, which is the ROOT node of the entire node tree)
Subnode:
Generally, the maximum subnode below the root node is the main document area.To access the body tag, write the following in the script:
Document. body
All text and HTML tags in the body area are document nodes, which are called text nodes and element nodes (or tag nodes) respectively. We all know that HTML is just text,
No matter what the web page is, it must be composed of these two nodes, and it can only be composed of these two nodes.
Relationship between nodes:
The relationship between nodes is also one of the most important joints in DOM. To correctly reference a Node object, you must understand the description of each node in the node tree. In DHTML,
The Javascript script uses a complete set of methods and attributes of each node object to describe another Node object.
Absolute reference of a node:
Return the root node of the document
Document.doc umentElement
Returns the tag node that is being attacked in the current document.
Document. activeElement
Back to the source node with the mouse removed
Event. fromElement
Back to the source node
Event. toElement
Returns the source node of the activation event.
Event. srcElement
Relative reference of a node: (set the current peer node to a node)
Back to parent node
Node. parentNode
Node. parentElement
Return the child node set (including text nodes and label nodes)
Node. childNodes
Returns a set of child tag nodes.
Node. children
Returns a set of child text nodes.
Node. textNodes
Returns the first subnode.
Node. firstChild
Returns the last subnode.
Node. lastChild
Returns the same node
Node. nextSibling
Returns the same node.
Node. previussibling
Node operations: (set the current node to node)
Add a label node handle:
Document. createElement (sNode) // The name of the node label to be added. For example, newnode = document. createElement ("p ");
1. Add nodes:
Append a subnode:
Node. appendChild (oNode) // node handle newly added by oNode, for example, node. appendChild (newnode)
Application label Node
Node. applyElment (oNode, sWhere) // node handle newly added by oNode. sWhere has two values: outside/inside, which are added to the current node or inside.
Insert Node
Inode. insertBefore ()
Node. insertAdjacentElement ()
Node. replaceAdjacentText ()
2. Modify nodes:
Delete a node
Node. remove ()
Node. removeChild ()
Node. removeNode ()
Replace Node
Node. replaceChild ()
Node. replaceNode ()
Node. swapNode ()
2. Copy nodes:
Return copy node reference
Node. cloneNode (bAll) // bAll is a Boolean value. true/false indicates whether to clone all child nodes of the node.
3. node Information
Include a node?
Node. contains ()
Indicates whether a subnode exists.
Node. hasChildNodes ()
**************************************** ***************
The following describes how to operate xml in javascript.

The Code is as follows:


Related Article

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.