gpt4 book ai didi

html - "XML Parsing Error"上的自定义页面或操作

转载 作者:行者123 更新时间:2023-11-28 01:53:58 32 4
gpt4 key购买 nike

问题

有没有可能通过HTTP header告诉浏览器?或 html代码在 XML Parsing Error 时做什么发生?也许像X-OnXmlParsingError , <meta name="onXmlParsingError" href="http://example.com"/>

附加信息

更多信息:我生成 XHTML使用 application/xhtml+xml 将代码发送到浏览器 header 。所以,当我的 xhtml 出现问题时代码,浏览器而不是我漂亮的网页显示XML Parsing Error - 这是预期的行为。但我想更改它,并告诉每个浏览器在发生此错误时该怎么做。例如,重定向到带有一些友好消息的肯定格式错误的自定义页面。

我知道我可以在服务器端解析输出代码,但我不想这样。它的效率非常低,并且出现格式错误的代码的可能性……几乎为 0,但仍然如此。

浏览器

歌剧

hides the problem :

(...) we've decided to stop throwing draconian XML parsing failed error messages, and instead, attempt to reparse the document automatically as HTML. Instead of showing an error message in the browser, it's now dumped to the console, so as a developer, you can still find XML parsing error warnings in Opera Dragonfly and the Error Console if you want to.

火狐

生成

<parserror>(...)</parseerror>

而不是正常的 html , 所以很容易通过 document.documentElement === 'html' 检测到错误.

服务器端解决方法

除了问题要求,最快的(1秒内2500次检查,T4200 @ 2.00Ghz)PHP我发现的验证器是:

<?php
// returns 1 on success and 0 on failure
xml_parse(xml_parser_create(), $stringWithHtmlCode) == 1

我强烈建议阅读已接受答案下的评论。

最佳答案

为什么不通过 XMLHttpRequest(或早期的 IE 回退)检索 XHTML,并检查您请求 xmlhttp.resposeXML 的能力。如果这样做会引发异常或返回 null,则重定向到您的错误页面。否则,使用 window.onload = function() { document.write(xmlhttp.responseText) 重写文档; };

关于html - "XML Parsing Error"上的自定义页面或操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18303763/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com