javasript解析xml

以下是生成处理xml的代码 ActiveXObject

function loadXMLDoc(dname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument(“”,”",null);
}
else
{
alert(‘Your browser cannot handle this script’);
}
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}

然后就可以使用xmlDoc了
例如: xmlDoc=loadXMLDoc(“books.xml”);
var x=xmlDoc.getElementsByTagName(‘book’);
var newel
for (i=0;i
{
newel=xmlDoc.createElement(‘edition’);
x[i].appendChild(newel);
}
 

你可能感兴趣的:(xml,IE,Opera,Microsoft,firefox)