{"id":243390,"date":"2022-06-05T09:30:15","date_gmt":"2022-06-05T01:30:15","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=243390"},"modified":"2022-05-23T14:31:24","modified_gmt":"2022-05-23T06:31:24","slug":"dom-parser-errors","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/dom-parser-errors.html","title":{"rendered":"XML DOM \u89e3\u6790\u5668\u9519\u8bef\u6982\u8ff0"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5f53 Firefox \u9047\u5230\u89e3\u6790\u5668\u9519\u8bef\uff0c\u5b83\u4f1a\u8f7d\u5165\u4e00\u4e2a\u5305\u542b\u9519\u8bef\u7684 XML \u6587\u6863\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5728 Firefox \u4e2d\u7684\u89e3\u6790\u5668\u9519\u8bef<\/strong><\/div>\n

\u5728\u60a8\u8bd5\u56fe\u6253\u5f00\u4e00\u4e2a XML \u6587\u6863\u65f6\uff0c\u5c31\u53ef\u80fd\u53d1\u751f\u4e00\u4e2a\u89e3\u6790\u5668\u9519\u8bef\uff08parser-error\uff09\u3002<\/p>\n

\u4e0e Internet Explorer \u6d4f\u89c8\u5668\u4e0d\u540c\uff0c\u5982\u679c Firefox \u9047\u5230\u9519\u8bef\uff0c\u5b83\u4f1a\u8f7d\u5165\u5305\u542b\u9519\u8bef\u63cf\u8ff0\u7684 XML \u6587\u6863\u4e2d\u3002<\/p>\n

XML \u9519\u8bef\u6587\u6863\u7684\u6839\u8282\u70b9\u7684\u540d\u79f0\u662f \"parsererror\"\u3002\u8fd9\u662f\u7528\u6765\u68c0\u67e5\u662f\u5426\u6709\u9519\u8bef\u3002<\/p>\n

XML \u9519\u8bef\uff08XML Error\uff09<\/strong><\/div>\n

\u5728\u4e0b\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f1a\u8ba9\u89e3\u6790\u5668\u52a0\u8f7d\u4e00\u4e2a\u5f62\u5f0f\u4e0d\u826f\u7684 XML \u6587\u6863\u3002<\/p>\n

\u5b9e\u4f8b<\/p>\n

\r\nxmlDoc=document.implementation.createDocument(\"\",\"\",null);\r\nxmlDoc.async=false;\r\nxmlDoc.load(\"note_error.xml\");
\r\nif (xmlDoc.documentElement.nodeName==\"parsererror\")\r\n{\r\nerrStr=xmlDoc.documentElement.childNodes[0].nodeValue;\r\nerrStr=errStr.replace(\/<\/g, \"&lt;\");\r\ndocument.write(errStr);\r\n}\r\nelse\r\n{\r\ndocument.write(\"XML is valid\");\r\n}\r\n<\/pre>\n

\u5b9e\u4f8b\u89e3\u91ca\uff1a<\/p>\n

    \n
  1. \u52a0\u8f7d XML \u6587\u4ef6<\/li>\n
  2. \u68c0\u67e5\u6839\u8282\u70b9\u7684\u8282\u70b9\u540d\u79f0\u662f\u5426\u662f \"parsererror\"<\/li>\n
  3. \u628a\u9519\u8bef\u5b57\u7b26\u4e32\u8f7d\u5165\u53d8\u91cf \"errStr\"<\/li>\n
  4. \u5728\u9519\u8bef\u5b57\u7b26\u4e32\u7f16\u5199\u4e3a HTML \u4e4b\u524d\uff0c\u628a \"<\" \u5b57\u7b26\u66ff\u6362\u4e3a \"<\"<\/li>\n<\/ol>\n

    \u6ce8\u610f\uff1a\u5b9e\u9645\u4e0a\uff0c\u53ea\u6709 Internet Explorer \u4f1a\u7528 DTD \u68c0\u67e5\u60a8\u7684 XML\uff0cFirefox \u4e0d\u4f1a\u3002<\/p>\n

    \u8de8\u6d4f\u89c8\u5668\u7684\u9519\u8bef\u68c0\u67e5<\/strong><\/div>\n

    \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a XML \u52a0\u8f7d\u51fd\u6570\uff0c\u5728 Internet Explorer \u548c Firefox \u4e2d\u68c0\u67e5\u89e3\u6790\u5668\u9519\u8bef\uff1a<\/p>\n

    \u5b9e\u4f8b<\/p>\n

    function loadXMLDocErr(dname)\r\n{\r\ntry \/\/Internet Explorer\r\n{\r\nxmlDoc=new ActiveXObject(\"Microsoft.XMLDOM\");\r\nxmlDoc.async=false;\r\nxmlDoc.load(dname);\r\n\r\nif (xmlDoc.parseError.errorCode != 0)\r\n{\r\nalert(\"Error in line \" + xmlDoc.parseError.line +\r\n\" position \" + xmlDoc.parseError.linePos +\r\n\"nError Code: \" + xmlDoc.parseError.errorCode +\r\n\"nError Reason: \" + xmlDoc.parseError.reason +\r\n\"Error Line: \" + xmlDoc.parseError.srcText);\r\nreturn(null);\r\n}\r\n}\r\ncatch(e)\r\n{\r\ntry \/\/Firefox\r\n{\r\nxmlDoc=document.implementation.createDocument(\"\",\"\",null);\r\nxmlDoc.async=false;\r\nxmlDoc.load(dname);\r\nif (xmlDoc.documentElement.nodeName==\"parsererror\")\r\n{\r\nalert(xmlDoc.documentElement.childNodes[0].nodeValue);\r\nreturn(null);\r\n}\r\n}\r\ncatch(e) {alert(e.message)}\r\n}\r\ntry\r\n{\r\nreturn(xmlDoc);\r\n}\r\ncatch(e) {alert(e.message)}\r\nreturn(null);\r\n}<\/pre>\n

    \u5b9e\u4f8b\u89e3\u91ca - Internet Explorer\uff1a<\/p>\n

      \n
    1. \u7b2c\u4e00\u884c\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u5fae\u8f6f XML \u6587\u6863\u5bf9\u8c61\u3002<\/li>\n
    2. \u7b2c\u4e8c\u884c\u5173\u95ed\u5f02\u6b65\u52a0\u8f7d\uff0c\u786e\u4fdd\u5728\u6587\u6863\u5b8c\u5168\u52a0\u8f7d\u4e4b\u524d\u89e3\u6790\u5668\u4e0d\u4f1a\u7ee7\u7eed\u6267\u884c\u811a\u672c\u3002<\/li>\n
    3. \u7b2c\u4e09\u884c\u544a\u77e5\u89e3\u6790\u5668\u52a0\u8f7d\u540d\u4e3a \"note_error.xml\" \u7684 XML \u6587\u6863\u3002<\/li>\n
    4. \u5982\u679c parseError \u5bf9\u8c61\u7684 ErrorCode \u5c5e\u6027\u548c \"0\" \u4e0d\u540c\uff0c\u63d0\u9192\u9519\u8bef\u5e76\u9000\u51fa\u51fd\u6570\u3002<\/li>\n
    5. \u5982\u679c ErrorCode \u5c5e\u6027\u4e3a \"0\"\uff0c\u8fd4\u56de XML \u6587\u6863\u3002<\/li>\n<\/ol>\n

      \u5b9e\u4f8b\u89e3\u91ca - Firefox\uff1a<\/p>\n

        \n
      1. \u7b2c\u4e00\u884c\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684XML\u6587\u6863\u5bf9\u8c61\u3002<\/li>\n
      2. \u7b2c\u4e8c\u884c\u5173\u95ed\u5f02\u6b65\u52a0\u8f7d\uff0c\u786e\u4fdd\u5728\u6587\u6863\u5b8c\u5168\u52a0\u8f7d\u4e4b\u524d\u89e3\u6790\u5668\u4e0d\u4f1a\u7ee7\u7eed\u6267\u884c\u811a\u672c\u3002<\/li>\n
      3. \u7b2c\u4e09\u884c\u544a\u77e5\u89e3\u6790\u5668\u52a0\u8f7d\u540d\u4e3a \"note_error.xml\" \u7684 XML \u6587\u6863\u3002<\/li>\n
      4. \u5982\u679c\u8fd4\u56de\u7684\u6587\u6863\u662f\u4e00\u4e2a\u9519\u8bef\u7684\u6587\u6863\uff0c\u63d0\u9192\u9519\u8bef\u5e76\u9000\u51fa\u51fd\u6570\u3002<\/li>\n
      5. \u5982\u679c\u6ca1\u6709\uff0c\u5219\u8fd4\u56de XML \u6587\u6863\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"

        \u5728\u60a8\u8bd5\u56fe\u6253\u5f00\u4e00\u4e2a XML \u6587\u6863\u65f6\uff0c\u5c31\u53ef\u80fd\u53d1\u751f\u4e00\u4e2a\u89e3\u6790\u5668\u9519\u8bef\uff08parser-error\uff09\u3002 \u4e0e Internet […]<\/p>\n","protected":false},"author":1481,"featured_media":243392,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-243390","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/243390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=243390"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/243390\/revisions"}],"predecessor-version":[{"id":243395,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/243390\/revisions\/243395"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/243392"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=243390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=243390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=243390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}