XML and JSON validation

Source: Internet
Author: User

function Chkjson (Strjson) {//To determine if the JSON format is correct
if (Strjson = = NULL | | strjson = = "")
return true;

try {
Json.parse (Strjson);
return true;
}
catch (ex) {
return false;
}
}
function Validatexml (strxml, msg) {
Debugger
msg = msg + "\r\r error message: \ r";
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 (msg + txt);
//return false;
//} else {
////alert ("No error Found");
//return true;
//}
//}
//code for Mozilla, Firefox, Opera, Chrome, etc.
//Else
if (document.implementation.createDocument) {
var parser = new Domparser ();
//var te XT = TXT;
var xmldoc = parser.parsefromstring (strxml, "text/xml");

if (XmlDoc.documentElement.nodeName = = "ParserError") {
Alert (msg + xmldoc.documentelement.childnodes[0]. NodeValue);
return false;
} else {
//alert ("No Errors Found");
return true;
}
}
////code for IE
else if (window. ActiveXObject) {
Alert (' Please use Chrome browser ');
return false;
}
Else {
Alert (' Your browser cannot process XML validation ');
return false;
}
}

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.