小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

js xmlDom

 昵稱16784427 2015-01-08

1. 加載XML文檔:

var xmlDom = new ActiveXObject("MSXML2.DOMDocument"); 
xmlDom.load("filename.xml"); //加載XML文件

2. 訪問節(jié)點(diǎn):

var root = xmlDom.documentElement;//獲取根節(jié)點(diǎn) 
var nodeList = root.childNodes;  //獲取節(jié)點(diǎn)的所有子節(jié)點(diǎn) 
var node = nodeList[i]; 
var name = node.attributes[0].value;//獲取節(jié)點(diǎn)的第一個(gè)屬性的值 
var xmlElement = node.xml;//包含起始標(biāo)簽+內(nèi)容+結(jié)束標(biāo)簽 
var content = xmlElement.childNodes[0].xml;//若xmlElement不包括子節(jié)點(diǎn),則可以獲得xmlElement標(biāo)簽中的內(nèi)容;若其包括子節(jié)點(diǎn),則獲得第一個(gè)子節(jié)點(diǎn)標(biāo)簽及其內(nèi)容; 
var content = xmlElement.text;

3. 添加節(jié)點(diǎn):

var newElement = xmlDom.createElement("element"); 
// 創(chuàng)建attribute屬性,并添加到element節(jié)點(diǎn)上 
var attribute = xmlDom.createAttribute("attribute"); 
attribute.value = "attrubuteValue"; 
newElement.setAttributeNode(name); 
 
// 創(chuàng)建subElement子節(jié)點(diǎn),并添加到newElement節(jié)點(diǎn)上 
var subElement = xmlDom.createElement("subElement"); 
newElement.text = "SubElementContent"; 
newElement.appendChild(subElement); 
//將newElement添加到根節(jié)點(diǎn)下 
root.appendChild(newElement); 

4. 刪除節(jié)點(diǎn):

var node = root.selectSingleNode("xpath"); 
if (node != null) 
     root.removeChild(node);

5. 保存節(jié)點(diǎn):

xmlDom.save("driver:\\dir\filename.xml");//保存XML文件

6. Xpath幾個(gè)例子:

authors 
authors/author 
authors/author/name 
authors/**//*/name 
authors/author/*            //*為通配符 
authors/author[nationality]/name      //用“[]”來限制只選取擁有nationality子節(jié)點(diǎn)的節(jié)點(diǎn) 
authors/author[nationality='Russian']/name //進(jìn)一步限制子節(jié)點(diǎn)nationality的值為'Russian' 
authors/author[@period="classical"]    //選取屬性period為"classical"的節(jié)點(diǎn) 
authors/author/@period         //選取節(jié)點(diǎn)的屬性

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多