JavaScript validation XML format

Source: Internet
Author: User

1<script>2 functionvalidatexml (xmlcontent)3 { 4     //errorCode 0 is xml correct, 1 is an XML error, 2 is not verifiable5     varXmldoc,errormessage,errorcode = 0; 6     //code for IE7     if(window. ActiveXObject)8     { 9xmldoc =NewActiveXObject ("Microsoft.XMLDOM"); TenXmldoc.async= "false";  One Xmldoc.loadxml (xmlcontent); A   -         if(xmldoc.parseerror.errorcode!=0)  -         {  theErrormessage= "Error code:" + XmlDoc.parseError.errorCode + "\ n";  -Errormessage=errormessage+ "Error Reason:" +XmlDoc.parseError.reason; -Errormessage=errormessage+ "Error Location:" +XmlDoc.parseError.line; -ErrorCode = 1;  +         }  -         Else  +         {  AErrorMessage = "properly formatted";  at         }  -     }  -     //code for Mozilla, Firefox, Opera, Chrome, safari,etc. -     Else if(document.implementation.createDocument) -     {  -         varParser=NewDomparser (); inxmldoc = parser.parsefromstring (xmlcontent, "Text/xml");  -         varError = Xmldoc.getelementsbytagname ("ParserError");  to         if(Error.length > 0)  +         {  -             if(xmldoc.documentelement.nodename== "ParserError"){  theErrorCode = 1;  *ErrorMessage = Xmldoc.documentelement.childnodes[0].nodevalue;  $}Else { Panax NotoginsengErrorCode = 1;  -ErrorMessage = Xmldoc.getelementsbytagname ("ParserError") [0].innerhtml;  the             }  +         }  A         Else  the         {  +ErrorMessage = "properly formatted";  -         }  $     }  $     Else  -     {  -ErrorCode = 2;  theErrorMessage = "Browser does not support validation and cannot validate XML correctness";  -     } Wuyi     return {  the"MSG": errormessage, -"Error_code": ErrorCode Wu     };  -}

Method invocation:

1 $ (document). Ready (function() {2     function() {3          $ (this). val () = = "" | |! Validatexml ($ (this). Val ()). Error_code? $ (this). Removeclass ("Bolder"): $ (this). AddClass ("bolder"); 4     }); 5 });

JavaScript validation XML format

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.