五、解析xml文件和字符串
ie中: xmlDoc = new ActionXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.load("books.xml"); //xmlDoc.loadXml(txt);
ff中:xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.async = "false"; (关闭异步加载,确保在文档完整加载之前,解析器不会继续执行脚本)。
xmlDoc.load("books.xml");
//parser = new DOMParser();
//xmlDoc = perser.parseFromString(txt,"text/xml");
六、
1、获取: nodeValue 获取节点的文本值。
getAttribute() 返回属性的值。
getAttributeNode() 返回属性的节点。
eg: xmlDoc.getElementsByTagname("title")[0].getAttribute("lang");
xmlDoc.getElementsByTagname("title")[0].getAttributeNode("lang").nodeValue;
2、改变: setAttribute()
3、删除: removeChild,removeAttribute()
4、替换: replaceChild(), 通过nodaValue替换。
5、创建: eg: new = xmlDoc.createElment("edition");
xmlDoc.getElementsByTagname("book").appendChild(new);
createAttribute()
eg: newatt = xmlDoc.creatAttribute("edition");
newatt.nodeValue = "first";
xmlDoc.getAttributeByTagname("title").setAttributeNode(newatt);
<