Guest User

Untitled

a guest
Sep 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. function validateXML(txt)
  2. {
  3. // code for IE
  4. if (window.ActiveXObject)
  5. {
  6. var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  7. xmlDoc.async=false;
  8. xmlDoc.loadXML(document.all(txt).value);
  9.  
  10. if(xmlDoc.parseError.errorCode!=0)
  11. {
  12. txt="Error Code: " + xmlDoc.parseError.errorCode + "\n";
  13. txt=txt+"Error Reason: " + xmlDoc.parseError.reason;
  14. txt=txt+"Error Line: " + xmlDoc.parseError.line;
  15. alert(txt);
  16. }
  17. else
  18. {
  19. alert("No errors found");
  20. }
  21. }
  22. // code for Mozilla, Firefox, Opera, etc.
  23. else if (document.implementation.createDocument)
  24. {
  25. var parser=new DOMParser();
  26. var text=document.getElementById(txt).value;
  27. var xmlDoc=parser.parseFromString(text,"text/xml");
  28.  
  29. if (xmlDoc.getElementsByTagName("parsererror").length>0)
  30. {
  31. checkErrorXML(xmlDoc.getElementsByTagName("parsererror")[0]);
  32. alert(xt)
  33. }
  34. else
  35. {
  36. alert("No errors found");
  37. }
  38. }
  39. else
  40. {
  41. alert('Your browser cannot handle XML validation');
  42. }
  43. }
Add Comment
Please, Sign In to add comment