search
HomeBackend DevelopmentXML/RSS TutorialXML Learning (2) Detailed explanation of DOM operations on XML documents

In the eyes of DOM, HTML is a tree-structured document like XML. Each node is treated as a Node object of various types. Each Node object has its own properties and methods, which can be used to traverse the entire document tree. DOM defines nodeType to represent the type of node

##Text Node.TEXT_NODE##Node.COMMENT_NODE8Commented text##DocumentFragmentAttr

The root node of the DOM tree is a Document object, and sometimes the document points to the entire document.

Most of the methods defined by Document are production methods, mainly used to create various types of nodes that can be inserted into the document. Commonly used Document methods are:

Interface

##nodeType Constant

nodeType value

Remarks

Element

Node.ELEMENT_NODE

1

##Element Node

##3

Text Node

Document

##Node.DOCUMENT_NODE

9

##document

Comment

Node.DOCUMENT_FRAGMENT_NODE

##11

document fragment

Node.ATTRIBUTE_NODE

##2

Node attributes

Commonly used methods of Element:

Method

Description

createAttribute()

Create with the specified name New Attr node.

createComment()

Use the specified string Create a new Comment node.

createElement()

Use the specified tag name Create a new Element node.

createTextNode()

Create with the specified text New TextNode node.

##getElementById()

Returns the Element node with the specified id attribute in the document.

##getElementsByTagName()

Returns the document with the specified All Element nodes of the tagname.

## Returns a Node##hasAttribute()removeAttribute()##setAttribute()Set the specified attribute For the specified string value, adds a new attribute if it does not exist. ##setAttributeNode()

##Method

Description

getAttribute()

Returns the value of the specified property as a string.

getAttributeNode()

In the form of Attr node Returns the value of the specified property.

##getElementsByTabName()

Array

Contains the descendant nodes of all Element nodes with the specified tag name, in the order they appear in the document.

If the element has the specified Name attribute, returns true.

Remove the specified attribute from the element.

##removeAttributeNode()

From the attribute list of the element Delete the specified Attr node.

Set the specified Attr node Added to the element's attribute list.

Commonly used attributes of Node objects:

##Return the next node in the form of Node The current node and its previous sibling nodes. If there is no such node, null is returned.

Common methods of Node objects:

Attributes

Description

##attributes

If the node is an Element, the attributes of the element are returned in the form of NamedNodeMap.

##childNodes

is stored in the form of Node[] The child nodes of the current node. If there are no child nodes, an empty array is returned.

firstChild

Returns the current node in the form of Node the first child node.

null if there are no child nodes.

lastChild

Returns the current node in the form of Node the last child node of . This is null if there are no child nodes.

nextSibling

Returns the next node that is the sibling of the current node in the form of Node. If there is no such node, null is returned.

nodeName

The name of the node, the Element node is Represents the tag name of the Element.

nodeType

represents the type of node.

##parentNode

Returns the current node in the form of Node 's parent node. If there is no parent node, this is null.

##previousSibling

Method

Description

##appendChild()

By adding a node to The childNodes[] group of the current node adds nodes to the document tree.

##cloneNode()

Copy the current node, or Copies the current node and all its descendant nodes.

hasChildNodes()

If the current node has children node, it will return true.

insertBefore()

Insert a document tree Node, positioned before the specified child node of the current node. If the node already exists, delete it and insert it in its place.

removeChild()

Remove from the document tree and returns the specified child node.

replaceChild()

Removes and returns the specified child node from the document tree , replace it with another node.


Getting the value of an element

The following code retrieves the text value of the first

element: <pre class='brush:php;toolbar:false;'>x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];txt=x.nodeValue; //其实应该先判断节点是否存在</pre><p>Result: txt = "Harry Potter"</p> <h2 id="Get-the-value-of-the-attribute">Get the value of the attribute</h2> <p>The following code retrieves the "<a href="http://www.php.cn/java/java-ymp-Lang.html" target="_blank">lang# of the first <title> element ##" Text value of the attribute:
txt=xmlDoc.getElementsByTagName("title")[0].getAttribute("lang");

Result: txt = "en"

Change the value of the element

The following code changes the first element Text value: <p><pre class='brush:php;toolbar:false;'>x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];x.nodeValue="Easy Cooking";</pre></p>Change the value of the attribute<h2></h2> The setAttribute() method can be used to change the value of an existing attribute, or create a new attribute. <p></p>The following code adds a new attribute named "edition" (with a value of "first") to each <book> element: <p><pre class='brush:php;toolbar:false;'>x=xmlDoc.getElementsByTagName("book");for(i=0;i<x.length;i++) { x[i].setAttribute("edition","first"); }</pre></p>Creating elements<h2></h2> The createElement() method creates a new element node. <p></p>createTextNode() method creates a new text node. <p></p>appendChild() method adds a child node to a node (after the last child node). <p></p>If you need to create a new element with text content, you need to create an element node and a text node at the same time. <p></p>The following code creates an element (<edition>) and then adds it to the first <book> element: <p><pre class='brush:php;toolbar:false;'>newel=xmlDoc.createElement("edition");</pre><pre class='brush:php;toolbar:false;'>newtext=xmlDoc.createTextNode("First");</pre><pre class='brush:php;toolbar:false;'>newel.appendChild(newtext);</pre><pre class='brush:php;toolbar:false;'>x=xmlDoc.getElementsByTagName("book");x[0].appendChild(newel);</pre></p>Example explanation:<h3></h3> <ol class=" list-paddingleft-2"> <li>Create <edition> element<p></p></edition> </li> <li>Create a text node with a value of "First"<p></p> </li> <li>Place this text node Append to <edition> element<p></p></edition> </li> <li>Append <edition> element to first <book> element<p></p></book></edition> </li> </ol>Delete element<h2></h2>removeChild() method deletes the specified node (or element). <p></p>The following code snippet will delete the first node in the first <book> element: <p><pre class='brush:php;toolbar:false;'>x=xmlDoc.getElementsByTagName("book")[0];x.removeChild(x.childNodes[0]);</pre></p>Example code<h2 id="pre-class-brush-php-toolbar-false-p-br-br-Code-highlighting-produced-by-Actipro-CodeHighlighter-freeware-br-http-www-CodeHighlighter-com-br-br-span-style-color-ff-span-span-style-color-html-span-span-style-color-ff-xmlns-span-span-style-color-ff-http-www-w-org-xhtml-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-head-span-span-style-color-ff-runat-span-span-style-color-ff-server-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-title-span-span-style-color-ff-span-span-style-color-title-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-script-span-span-style-color-ff-type-span-span-style-color-ff-text-a-href-http-www-php-cn-wiki-html-target-blank-javascript-a-span-span-style-color-ff-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-ff-function-span-span-style-background-color-f-f-f-color-parseXML-br-span-span-style-background-color-f-f-f-color-ff-try-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-Internet-Explorer-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlDoc-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-new-span-span-style-background-color-f-f-f-color-ActiveX-a-href-http-www-php-cn-wiki-html-target-blank-Object-a-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-Microsoft-XMLDOM-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-span-span-style-background-color-f-f-f-color-ff-catch-span-span-style-background-color-f-f-f-color-e-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-span-span-style-background-color-f-f-f-color-ff-try-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-Firefox-Mozilla-Opera-etc-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlDoc-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-document-implementation-createDocument-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-null-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-span-span-style-background-color-f-f-f-color-ff-catch-span-span-style-background-color-f-f-f-color-e-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-alert-e-message-br-span-span-style-background-color-f-f-f-color-ff-a-href-http-www-php-cn-wiki-html-target-blank-return-a-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlDoc-async-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-false-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-假如xml载入完毕执行以下-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlDoc-load-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-note-xml-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-ff-var-span-span-style-background-color-f-f-f-color-x-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-xmlDoc-getElementsByTagName-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-to-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlDoc-getElementsByTagName-to-setAttribute-a-href-http-www-php-cn-wiki-html-target-blank-date-a-nbsp-设置属性值-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlDoc-getElementsByTagName-to-childNodes-nodeValue-tiewang-设置文本节点值-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-a-href-http-www-php-cn-code-html-target-blank-循环-a-修改-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-for-i-i-x-length-i-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-if-x-i-childNodes-null-如果不存在问题-则添加-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-newText-xmlDoc-createTextNode-af-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-x-i-appendChild-newText-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-x-i-childNodes-nodeValue-af-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-循环添加-注意-如果把create放在-a-href-http-www-php-cn-code-html-target-blank-for循环-a-外面-则只能添加到最后一个-需要放在for里面-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-span-span-style-background-color-f-f-f-color-ff-for-span-span-style-background-color-f-f-f-color-i-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-i-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-x-length-i-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-ff-if-span-span-style-background-color-f-f-f-color-x-i-getElementsByTagName-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-too-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-null-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-newElemenet-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-xmlDoc-createElement-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-too-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-newText-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-xmlDoc-createTextNode-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-logo-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-newElemenet-setAttribute-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-id-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-newElemenet-appendChild-newText-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-x-i-appendChild-newElemenet-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-循环删除-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-for-i-i-x-length-i-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-if-x-i-getElementsByTagName-too-null-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-x-i-removeChild-x-i-getElementsByTagName-too-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-span-p-p-span-style-background-color-f-f-f-color-nbsp-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-span-style-font-family-Courier-New-background-color-f-f-f-nbsp-nbsp-nbsp-nbsp-nbsp-span-span-p-p-span-style-background-color-f-f-f-color-span-style-font-family-Courier-New-background-color-f-f-f-删除to-too-节点中的ID属性-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-for-i-i-x-length-i-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-if-x-i-getElementsByTagName-too-null-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-if-x-i-getElementsByTagName-too-getAttribute-id-null-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-x-i-getElementsByTagName-too-removeAttribute-id-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-span-br-span-span-style-background-color-f-f-f-color-ff-var-span-span-style-background-color-f-f-f-color-xmlHttp-br-br-span-span-style-background-color-f-f-f-color-ff-try-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-Firefox-Opera-Safari-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlHttp-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-new-span-span-style-background-color-f-f-f-color-XMLHttpRequest-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-span-span-style-background-color-f-f-f-color-ff-catch-span-span-style-background-color-f-f-f-color-e-br-br-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-Internet-Explorer-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-span-span-style-background-color-f-f-f-color-ff-try-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlHttp-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-new-span-span-style-background-color-f-f-f-color-ActiveXObject-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-Msxml-XMLHTTP-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-span-span-style-background-color-f-f-f-color-ff-catch-span-span-style-background-color-f-f-f-color-e-br-br-span-span-style-background-color-f-f-f-color-ff-try-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlHttp-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-new-span-span-style-background-color-f-f-f-color-ActiveXObject-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-Microsoft-XMLHTTP-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-span-span-style-background-color-f-f-f-color-ff-catch-span-span-style-background-color-f-f-f-color-e-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-alert-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-您的浏览器不支持AJAX-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-ff-return-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-false-span-span-style-background-color-f-f-f-color-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlHttp-onreadystatechange-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-function-span-span-style-background-color-f-f-f-color-nbsp-nbsp-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-onreadystatechange-属性存有处理服务器响应的-a-href-http-www-php-cn-wiki-html-target-blank-函数-a-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-span-span-style-background-color-f-f-f-color-ff-if-span-span-style-background-color-f-f-f-color-xmlHttp-readyState-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-readyState-属性存有服务器响应的-a-href-http-www-php-cn-code-html-target-blank-状态-a-信息-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-document-getElementById-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-to-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-innerHTML-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-xmlHttp-responseText-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-通过-responseText-属性来取回由服务器返回的数据-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-br-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlHttp-open-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-POST-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-receive-a-href-http-www-php-cn-wiki-html-target-blank-asp-a-x-type-xmlsave-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-ff-true-span-span-style-background-color-f-f-f-color-br-br-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-open-方法需要三个参数-第一个参数定义发送请求所使用的方法-GET-还是-POST-第二个参数规定服务器端脚本的-URL-第三个参数规定应当对请求进行异步地处理-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-xmlHttp-send-xmlDoc-nbsp-nbsp-nbsp-span-span-style-background-color-f-f-f-color-span-span-style-background-color-f-f-f-color-send-方法可将请求送往服务器-nbsp-nbsp-span-span-style-background-color-f-f-f-color-br-span-span-style-background-color-f-f-f-color-nbsp-nbsp-br-span-span-style-color-ff-span-span-style-color-script-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-head-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-body-span-span-style-color-ff-a-href-http-www-php-cn-wiki-html-target-blank-onload-a-span-span-style-color-ff-parseXML-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-form-span-span-style-color-ff-id-span-span-style-color-ff-form-span-span-style-color-ff-runat-span-span-style-color-ff-server-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-p-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-h-span-span-style-color-ff-id-span-span-style-color-ff-to-span-span-style-color-ff-span-span-style-color-h-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-h-span-span-style-color-ff-id-span-span-style-color-ff-value-span-span-style-color-ff-span-span-style-color-h-span-span-style-color-ff-span-span-style-color-br-br-br-span-span-style-color-ff-span-span-style-color-p-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-form-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-body-span-span-style-color-ff-span-span-style-color-br-span-span-style-color-ff-span-span-style-color-html-span-span-style-color-ff-span-p-pre"><pre class='brush:php;toolbar:false;'><p><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff;"><</span><span style="color: #800000;">html </span><span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">="http://www.w3.org/1999/xhtml"</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"><</span><span style="color: #800000;">head </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"><</span><span style="color: #800000;">title</span><span style="color: #0000ff;">></</span><span style="color: #800000;">title</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"><</span><span style="color: #800000;">script </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text/<a href="http://www.php.cn/wiki/48.html" target="_blank">javascript</a>"</span><span style="color: #0000ff;">></span><span style="background-color: #f5f5f5; color: #000000;"><br/></span><span style="background-color: #f5f5f5; color: #0000ff;">function</span><span style="background-color: #f5f5f5; color: #000000;"> parseXML() {<br/></span><span style="background-color: #f5f5f5; color: #0000ff;">try</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;">Internet Explorer</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> {<br/> xmlDoc </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">new</span><span style="background-color: #f5f5f5; color: #000000;"> ActiveX<a href="http://www.php.cn/wiki/60.html" target="_blank">Object</a>(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">Microsoft.XMLDOM</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br/> }<br/></span><span style="background-color: #f5f5f5; color: #0000ff;">catch</span><span style="background-color: #f5f5f5; color: #000000;"> (e) { <br/></span><span style="background-color: #f5f5f5; color: #0000ff;">try</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;">Firefox, Mozilla, Opera, etc.</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> {<br/> xmlDoc </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> document.implementation.createDocument(</span><span style="background-color: #f5f5f5; color: #000000;">""</span><span style="background-color: #f5f5f5; color: #000000;">, </span><span style="background-color: #f5f5f5; color: #000000;">""</span><span style="background-color: #f5f5f5; color: #000000;">, </span><span style="background-color: #f5f5f5; color: #0000ff;">null</span><span style="background-color: #f5f5f5; color: #000000;">);<br/> }<br/></span><span style="background-color: #f5f5f5; color: #0000ff;">catch</span><span style="background-color: #f5f5f5; color: #000000;"> (e) {<br/> alert(e.message);<br/></span><span style="background-color: #f5f5f5; color: #0000ff;"><a href="http://www.php.cn/wiki/135.html" target="_blank">return</a></span><span style="background-color: #f5f5f5; color: #000000;">;<br/> }<br/> }<br/> xmlDoc.async </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">false</span><span style="background-color: #f5f5f5; color: #000000;">; </span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;">假如xml载入完毕执行以下</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> xmlDoc.load(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">note.xml</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br/></span><span style="background-color: #f5f5f5; color: #0000ff;">var</span><span style="background-color: #f5f5f5; color: #000000;"> x </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> xmlDoc.getElementsByTagName(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">to</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br/></span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;"> xmlDoc.getElementsByTagName("to")[0].setAttribute("<a href="http://www.php.cn/wiki/1255.html" target="_blank">date</a>") = "1515"; //设置属性值</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue = "tiewang"; //设置文本节点值</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> <br/></span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;"> //<a href="http://www.php.cn/code/6276.html" target="_blank">循环</a>修改</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> for (i = 0; i < x.length; i++) {</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> if (x[i].childNodes[0] == null) { //如果不存在问题,则添加</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> newText1 = xmlDoc.createTextNode("af");</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> x[i].appendChild(newText1);</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> }</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> x[i].childNodes[0].nodeValue = "af";</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;"> }</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> //循环添加 //注意,如果把create放在<a href="http://www.php.cn/code/5913.html" target="_blank">for循环</a>外面,则只能添加到最后一个,需要放在for里面</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">for</span><span style="background-color: #f5f5f5; color: #000000;"> (i </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #000000;">0</span><span style="background-color: #f5f5f5; color: #000000;">; i </span><span style="background-color: #f5f5f5; color: #000000;"><</span><span style="background-color: #f5f5f5; color: #000000;"> x.length; i</span><span style="background-color: #f5f5f5; color: #000000;">++</span><span style="background-color: #f5f5f5; color: #000000;">) {<br/></span><span style="background-color: #f5f5f5; color: #0000ff;">if</span><span style="background-color: #f5f5f5; color: #000000;"> (x[i].getElementsByTagName(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">too</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">)[</span><span style="background-color: #f5f5f5; color: #000000;">0</span><span style="background-color: #f5f5f5; color: #000000;">] </span><span style="background-color: #f5f5f5; color: #000000;">==</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">null</span><span style="background-color: #f5f5f5; color: #000000;">) {<br/> newElemenet </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> xmlDoc.createElement(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">too</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br/> newText </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> xmlDoc.createTextNode(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">logo</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br/> newElemenet.setAttribute(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">id</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">, </span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">1</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br/> newElemenet.appendChild(newText); <br/> x[i].appendChild(newElemenet);<br/> }<br/> }<br/></span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;"> //循环删除</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> for (i = 0; i < x.length; i++) {</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> if (x[i].getElementsByTagName("too")[0] != null) {</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> x[i].removeChild(x[i].getElementsByTagName("too")[0]);</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> }</span><span style="background-color: #f5f5f5; color: #008000;"><br/>//</span><span style="background-color: #f5f5f5; color: #008000;"> }</span></p><p><span style="background-color: #f5f5f5; color: #008000;"> </span><span style="background-color: #f5f5f5; color: #008000;">    <br/></span><span style="background-color: #f5f5f5; color: #000000;"> <span style="font-family: Courier New; background-color: #f5f5f5;"> </span></span></p><p><span style="background-color: #f5f5f5; color: #000000;"><span style="font-family: Courier New; background-color: #f5f5f5;">      //删除to -> too 节点中的ID属性<br/> for (i = 0; i < x.length; i++) {<br/> if (x[i].getElementsByTagName("too")[0] != null) {<br/> if (x[i].getElementsByTagName("too")[0].getAttribute("id")!=null) {<br/> x[i].getElementsByTagName("too")[0].removeAttribute("id");<br/> }<br/> }<br/> }</span><br/></span><span style="background-color: #f5f5f5; color: #0000ff;">var</span><span style="background-color: #f5f5f5; color: #000000;"> xmlHttp;<br/><br/></span><span style="background-color: #f5f5f5; color: #0000ff;">try</span><span style="background-color: #f5f5f5; color: #000000;"> {<br/></span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;"> Firefox, Opera 8.0+, Safari</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> xmlHttp </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">new</span><span style="background-color: #f5f5f5; color: #000000;"> XMLHttpRequest();<br/> }<br/></span><span style="background-color: #f5f5f5; color: #0000ff;">catch</span><span style="background-color: #f5f5f5; color: #000000;"> (e) {<br/><br/></span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;"> Internet Explorer</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">try</span><span style="background-color: #f5f5f5; color: #000000;"> {<br/> xmlHttp </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">new</span><span style="background-color: #f5f5f5; color: #000000;"> ActiveXObject(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">Msxml2.XMLHTTP</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br/> }<br/></span><span style="background-color: #f5f5f5; color: #0000ff;">catch</span><span style="background-color: #f5f5f5; color: #000000;"> (e) {<br/><br/></span><span style="background-color: #f5f5f5; color: #0000ff;">try</span><span style="background-color: #f5f5f5; color: #000000;"> {<br/> xmlHttp </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">new</span><span style="background-color: #f5f5f5; color: #000000;"> ActiveXObject(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">Microsoft.XMLHTTP</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br/> }<br/></span><span style="background-color: #f5f5f5; color: #0000ff;">catch</span><span style="background-color: #f5f5f5; color: #000000;"> (e) {<br/> alert(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">您的浏览器不支持AJAX!</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">);<br/></span><span style="background-color: #f5f5f5; color: #0000ff;">return</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">false</span><span style="background-color: #f5f5f5; color: #000000;">;<br/> }<br/> }<br/> }<br/> xmlHttp.onreadystatechange </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">function</span><span style="background-color: #f5f5f5; color: #000000;">() { </span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;">onreadystatechange 属性存有处理服务器响应的<a href="http://www.php.cn/wiki/145.html" target="_blank">函数</a></span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #0000ff;">if</span><span style="background-color: #f5f5f5; color: #000000;"> (xmlHttp.readyState </span><span style="background-color: #f5f5f5; color: #000000;">==</span><span style="background-color: #f5f5f5; color: #000000;"> </span><span style="background-color: #f5f5f5; color: #000000;">4</span><span style="background-color: #f5f5f5; color: #000000;">) { </span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;">readyState 属性存有服务器响应的<a href="http://www.php.cn/code/8243.html" target="_blank">状态</a>信息</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> document.getElementById(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">to</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">).innerHTML </span><span style="background-color: #f5f5f5; color: #000000;">=</span><span style="background-color: #f5f5f5; color: #000000;"> xmlHttp.responseText; </span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;">通过 responseText 属性来取回由服务器返回的数据</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> }<br/> }<br/> xmlHttp.open(</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">POST</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">, </span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">receive.<a href="http://www.php.cn/wiki/1519.html" target="_blank">asp</a>x?type=xmlsave</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">, </span><span style="background-color: #f5f5f5; color: #0000ff;">true</span><span style="background-color: #f5f5f5; color: #000000;">); <br/><br/></span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;"> open() 方法需要三个参数。第一个参数定义发送请求所使用的方法(GET 还是 POST)。第二个参数规定服务器端脚本的 URL。第三个参数规定应当对请求进行异步地处理。</span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> xmlHttp.send(xmlDoc); </span><span style="background-color: #f5f5f5; color: #008000;">//</span><span style="background-color: #f5f5f5; color: #008000;">send() 方法可将请求送往服务器 </span><span style="background-color: #f5f5f5; color: #008000;"><br/></span><span style="background-color: #f5f5f5; color: #000000;"> }<br/></span><span style="color: #0000ff;"></</span><span style="color: #800000;">script</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"></</span><span style="color: #800000;">head</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"><</span><span style="color: #800000;">body </span><span style="color: #ff0000;"><a href="http://www.php.cn/wiki/1467.html" target="_blank">onload</a></span><span style="color: #0000ff;">="parseXML()"</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"><</span><span style="color: #800000;">form </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="form1"</span><span style="color: #ff0000;"> runat</span><span style="color: #0000ff;">="server"</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"><</span><span style="color: #800000;">p</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"><</span><span style="color: #800000;">h1 </span><span style="color: #ff0000;">id </span><span style="color: #0000ff;">= "to"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">h1</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"><</span><span style="color: #800000;">h1 </span><span style="color: #ff0000;">id </span><span style="color: #0000ff;">="value"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">h1</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/><br/><br/></span><span style="color: #0000ff;"></</span><span style="color: #800000;">p</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"></</span><span style="color: #800000;">form</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"></</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span><span style="color: #000000;"><br/></span><span style="color: #0000ff;"></</span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span></p></pre></h2> <p></p></book></book></edition></book>

The above is the detailed content of XML Learning (2) Detailed explanation of DOM operations on XML documents. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
RSS & XML: Understanding the Dynamic Duo of Web ContentRSS & XML: Understanding the Dynamic Duo of Web ContentApr 19, 2025 am 12:03 AM

RSS and XML are tools for web content management. RSS is used to publish and subscribe to content, and XML is used to store and transfer data. They work with content publishing, subscriptions, and update push. Examples of usage include RSS publishing blog posts and XML storing book information.

RSS Documents: The Foundation of Web SyndicationRSS Documents: The Foundation of Web SyndicationApr 18, 2025 am 12:04 AM

RSS documents are XML-based structured files used to publish and subscribe to frequently updated content. Its main functions include: 1) automated content updates, 2) content aggregation, and 3) improving browsing efficiency. Through RSSfeed, users can subscribe and get the latest information from different sources in a timely manner.

Decoding RSS: The XML Structure of Content FeedsDecoding RSS: The XML Structure of Content FeedsApr 17, 2025 am 12:09 AM

The XML structure of RSS includes: 1. XML declaration and RSS version, 2. Channel (Channel), 3. Item. These parts form the basis of RSS files, allowing users to obtain and process content information by parsing XML data.

How to Parse and Utilize XML-Based RSS FeedsHow to Parse and Utilize XML-Based RSS FeedsApr 16, 2025 am 12:05 AM

RSSfeedsuseXMLtosyndicatecontent;parsingtheminvolvesloadingXML,navigatingitsstructure,andextractingdata.Applicationsincludebuildingnewsaggregatorsandtrackingpodcastepisodes.

RSS Documents: How They Deliver Your Favorite ContentRSS Documents: How They Deliver Your Favorite ContentApr 15, 2025 am 12:01 AM

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

Building Feeds with XML: A Hands-On Guide to RSSBuilding Feeds with XML: A Hands-On Guide to RSSApr 14, 2025 am 12:17 AM

The steps to build an RSSfeed using XML are as follows: 1. Create the root element and set the version; 2. Add the channel element and its basic information; 3. Add the entry element, including the title, link and description; 4. Convert the XML structure to a string and output it. With these steps, you can create a valid RSSfeed from scratch and enhance its functionality by adding additional elements such as release date and author information.

Creating RSS Documents: A Step-by-Step TutorialCreating RSS Documents: A Step-by-Step TutorialApr 13, 2025 am 12:10 AM

The steps to create an RSS document are as follows: 1. Write in XML format, with the root element, including the elements. 2. Add, etc. elements to describe channel information. 3. Add elements, each representing a content entry, including,,,,,,,,,,,. 4. Optionally add and elements to enrich the content. 5. Ensure the XML format is correct, use online tools to verify, optimize performance and keep content updated.

XML's Role in RSS: The Foundation of Syndicated ContentXML's Role in RSS: The Foundation of Syndicated ContentApr 12, 2025 am 12:17 AM

The core role of XML in RSS is to provide a standardized and flexible data format. 1. The structure and markup language characteristics of XML make it suitable for data exchange and storage. 2. RSS uses XML to create a standardized format to facilitate content sharing. 3. The application of XML in RSS includes elements that define feed content, such as title and release date. 4. Advantages include standardization and scalability, and challenges include document verbose and strict syntax requirements. 5. Best practices include validating XML validity, keeping it simple, using CDATA, and regularly updating.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment