/**
* 支持chrome, firefox, ie的xml验证
*/
function validateXML(txt){
// code for IE
if (window.ActiveXObject){
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(txt);
if(xmlDoc.parseError.errorCode!=0){
//txt="Error Code: " + xmlDoc.parseError.errorCode + "\n";
//txt=txt+"Error Reason: " + xmlDoc.parseError.reason;
//txt=txt+"Error Line: " + xmlDoc.parseError.line;
//alert(txt);
//Ext.Msg.alert("警告","XML验证错误!");
return false;
}else{
//alert("XML验证通过!");
return true;
}
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation.createDocument){
var parser=new DOMParser();
var xmlDoc=parser.parseFromString(txt,"text/xml");
if (xmlDoc.documentElement.nodeName=="parsererror" || xmlDoc.documentElement.firstChild.nodeName=="parsererror"){
//Ext.Msg.alert("警告","XML验证错误!");
return false;
}else{
//alert("XML验证通过!");
return true;
}
}
}
JavaScript验证XML
最新推荐文章于 2024-05-28 11:44:38 发布