国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
XML DOM Remove Nodes

XML DOM Remove Nodes


Examples

In the examples below, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().

Remove an element
This example uses removeChild() to remove the last <book> element from the loaded XML.

Remove text from a text node
This example uses deleteData() to remove text from a text node in the loaded XML.

Remove an attribute
This example uses removeAttribute() to remove all "category" attributes from the loaded XML.

Use removeAttributeNode()
This example uses removeAttributeNode() to remove all "category" attributes from the loaded XML.


Remove an Element

The removeChild() method can be used to remove a specified node.

The following code fragment will remove the last <book> element from the loaded xml:

//check if last child node is an element node            function get_lastchild(n)            {            var x=n.lastChild;            while (x.nodeType!=1)            {            x=x.previousSibling;            }            return x;            }
xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.documentElement;
x.removeChild(get_lastchild(x));

Note: Internet Explorer will skip white-space text nodes that are generated between nodes (e.g. new-line characters), while Mozilla will not. So, in the example above, the get_lastchild() function checks the node type of the last child node of the parameter.

Element nodes has a nodeType of 1, so if not the last child of the node in the parameter is an element node, it moves to the previous node, and checks if this node is an element node. This continues until the last child node (which must be an element node) is found. This way, the result will be correct in both Internet Explorer and Mozilla.


Remove Text From an Element

The deleteData() method is used to remove data from a text node.

The deleteData() method has two parameters:

  • offset - Where to begin removing characters. Offset value starts at zero
  • count - How many characters to delete

The following code fragment will remove the first nine characters from the first <title> element in the loaded XML:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
x.deleteData(0,9);
 

Remove an Attribute

The removeAttribute() method is used to remove an attribute node.

The following code fragment will remove all "category" attributes in each <book> element:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName(‘book‘);
for(i=0;i<x.length;i++)            {            x.item(i).removeAttribute(‘category‘);            }
 

removeAttributeNode()

The removeAttributeNode() method is used to remove an attribute node.

The following code fragment will remove all "category" attributes in each <book> element:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName(‘book‘);
for(i=0;i<x.length;i++)            {            attnode=x.item(i).getAttributeNode("category")            old_att=x.item(i).removeAttributeNode(attnode);            document.write("Removed attribute: " + old_att.name + "<br />");            }

Output:

Removed attribute: category            Removed attribute: category            Removed attribute: category            Removed attribute: category



本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Javascript 操作XML
PHP 生成xml簡(jiǎn)單實(shí)例代碼
dom4j(Version 1.6.1)快速入門
應(yīng)用MSXML的DOM模型處理XML
XML DOM介紹
xml
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服