zoukankan      html  css  js  c++  java
  • XML and JSON 验证

    function ChkJson(strJson) { //判断Json格式是否正确
    if (strJson == null || strJson == "")
    return true;

    try {
    JSON.parse(strJson);
    return true;
    }
    catch (ex) {
    return false;
    }
    }
    function validateXML(strXml, msg) {
    debugger;
    msg = msg + " 错误信息: ";
    // // 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 + " ";
    // txt = txt + "Error Reason: " + xmlDoc.parseError.reason;
    // txt = txt + "Error Line: " + xmlDoc.parseError.line;
    // alert(msg + txt);
    // return false;
    // } else {
    // //alert("没有发现错误");
    // return true;
    // }
    // }
    // code for Mozilla, Firefox, Opera, Chrome, etc.
    // else
    if (document.implementation.createDocument) {
    var parser = new DOMParser();
    //var text = txt;
    var xmlDoc = parser.parseFromString(strXml, "text/xml");

    if (xmlDoc.documentElement.nodeName == "parsererror") {
    alert(msg + xmlDoc.documentElement.childNodes[0].nodeValue);
    return false;
    } else {
    //alert("没有发现错误");
    return true;
    }
    }
    // // code for IE
    else if (window.ActiveXObject) ){
    alert('请使用Chrome浏览器');
    return false;
    }
    else {
    alert('您的浏览器无法处理XML验证');
    return false;
    }
    }

  • 相关阅读:
    windbg学习.expr和masm表达式
    ThisCall调用分析
    windbg学习 gc j(Execute IfElse).if
    windbg学习¥{} Alias Interpreter 别名解释器
    windbg学习!vadump和.hh和!vprotc
    windbg学习 .lines
    windbg学习条件断点
    $<, $><, $$<, $$><, $$>a< (Run Script File)
    windbg学习?? 和 ?
    vimbook–OPL –official publications library
  • 原文地址:https://www.cnblogs.com/Michael-W/p/3716211.html
Copyright © 2011-2022 走看看