Process and traverse XML document DOM element attributes and method Collation _ Basics

Source: Internet
Author: User
Tags tag name tagname unique id
DOM element properties for processing XML documents
Copy Code code as follows:

ChildNodes: Returns an array of all child elements of the current element;
FirstChild: Returns the first subordinate child element of the current element;
LastChild: Returns the last child element of the current element;
NextSibling: Returns the element immediately following the current element;
Noedvalue: Specifies the read/write property that represents the value of the element;
ParentNode: Returns the parent node of the element;
PreviousSibling: Returns the element immediately preceding the current element;

Dom element method for traversing an XML document
Copy Code code as follows:

getElementById (ID) (document): Gets the element in the document with the specified unique id attribute value;
getElementsByTagName (name): Returns an array of child elements of the specified tag name in the current element;
HasChildNodes (): Returns a Boolean value indicating whether the element has child elements;
GetAttribute (name): Returns the attribute value of the element, which is specified by name;

The consortium DOM properties and methods used to dynamically create content
Copy Code code as follows:

Document.createelement (tagName) : The CreateElement method on a Document object can create an element that is specified by tagname, and if a string div is used as a method parameter, a DIV element is generated;
document.createTextNode (text) : The createTextNode method of the Document object creates a node that contains static text;
<element>.appendchild (Childnode) : The AppendChild method adds the specified node to the list of child nodes of the current element (as a new child node). For example, you can add an option element as a child of a SELECT element;
<element>.getattriture (name): These methods get and set the value of the Name property in the element;
<element >.setattritube (Name,value): Each of these methods gets and sets the value of the Name property in the element;
<element>.insertbefore (Newnode,targetnode) : This method inserts the node newnode as a child of the current element in front of the targetnode element;
<element>.removeattribute (name): This method deletes the property name from the element;
< Element>.removechild (Childnode): This method deletes the child element Childnode from the element;
<element>.replacechild (Newnode,oldnode) : This method replaces the node OldNode with the node NewNode
<element>.haschildnodes (): This method returns a Boolean value that specifies whether the element has child 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.