以下代码适用于Chrome,但我无法通过Firefox运行:
var ans = XML in string format
var xmlDoc;
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(ans,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(txt);
}
alert(xmlDoc.getElementsByTagName("Template")[0]); // <-- return undefined in firefox