Created
April 5, 2012 09:33
-
-
Save p3drosola/2309512 to your computer and use it in GitHub Desktop.
Javascript XML validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validateXML(txt) | |
{ | |
// code for IE | |
if (window.ActiveXObject) | |
{ | |
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); | |
xmlDoc.async=false; | |
xmlDoc.loadXML(document.all(txt).value); | |
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); | |
} | |
else | |
{ | |
alert("No errors found"); | |
} | |
} | |
// code for Mozilla, Firefox, Opera, etc. | |
else if (document.implementation.createDocument) | |
{ | |
var parser=new DOMParser(); | |
var text=document.getElementById(txt).value; | |
var xmlDoc=parser.parseFromString(text,"text/xml"); | |
if (xmlDoc.getElementsByTagName("parsererror").length>0) | |
{ | |
checkErrorXML(xmlDoc.getElementsByTagName("parsererror")[0]); | |
alert(xt) | |
} | |
else | |
{ | |
alert("No errors found"); | |
} | |
} | |
else | |
{ | |
alert('Your browser cannot handle XML validation'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cannot find name 'ActiveXObject'.
I am getting this error.