XML DOM appendChild() 方法

XML DOM – Node 对象

定义和用法

appendChild() 方法把新的子节点追加到节点的子节点列表的末尾。

该方法返回新的子节点。

语法

appendChild(newchild)

参数描述
newchild要追加的节点。

实例

下面的代码片段使用 loadXMLDoc() 把 "books.xml" 载入 xmlDoc 中,创建节点(<edition>),并把它添加到第一个 <book> 节点的最后一个子节点的后面:

xmlDoc=loadXMLDoc("books.xml");

newel=xmlDoc.createElement("edition");

x=xmlDoc.getElementsByTagName("book")[0];
x.appendChild(newel);

document.write(x.getElementsByTagName("edition")[0].nodeName);

Demos

appendChild() - 向所有的 <book> 节点追加一个子节点

XML DOM – Node 对象