【问题标题】:Content-type `application/xml` is displaying flattened text (loosing XML structure) in Firefox内容类型 `application/xml` 在 Firefox 中显示扁平文本(失去 XML 结构)
【发布时间】:2021-09-03 06:26:06
【问题描述】:

(基本上和Why XML file is not rendered properly in Firefox?是同一个问题,但似乎没有适合我的答案)

我编写了一个发送 XML 输出的简单测试 HTTP 服务器(如application/xml)。 然而 Firefox 78.13.0esr 将其显示为纯文本,即它忽略了所有元素标签和空格。 无论如何,在查看“页面源”时,XML 会正确显示。

所以我想知道这是否是 Firefox 中的错误,或者我的测试服务器是否做错了什么(或者我误解了什么)。 唯一安装的扩展是 Adob​​e Acrobat PDF 扩展。

这是响应头:

HTTP/1.1 200 All bits are up
Date: Fri, 03 Sep 2021 06:02:29 GMT
Server: libwww-perl-daemon/6.01
Content-Length: 604
Content-Type: application/xml
Charset: utf-8

这是内容:

<?xml version="1.0" encoding="utf-8"?>
<MonitoringOutput id="foo-test" version="0.1">
  <description>a simple test only</description>
  <exit_code>0</exit_code>
  <status_string>OK</status_string>
  <info_string>response_time(passwd:nagios) is 0.006 (0)</info_string>
  <perf_string> passwd_nagios=0.006;0;0;0</perf_string>
  <perf_data count="1">
    <sample label="passwd_nagios">
      <label>passwd_nagios</label>
      <value>0.006</value>
      <thresholds>
        <warn end="0"/>
        <crit end="0"/>
      </thresholds>
      <range min="0"/>
    </sample>
  </perf_data>
</MonitoringOutput>

这就是 Firefox 显示的内容:

a simple test only 0 OK response_time(passwd:nagios) is 0.006 (0) passwd_nagios=0.006;0;0;0 passwd_nagios 0.006

注意:如果我将 JSON 发送为 application/json,那么 Firefox 会很好地显示它,甚至可以折叠部分内容。

【问题讨论】:

    标签: xml http firefox


    【解决方案1】:

    这可能是一个扩展,显然有很多人这样做。还有另一篇帖子here 就是关于它的。就我而言,它是“SwipeToNavigate”插件。

    【讨论】:

      【解决方案2】:

      您可以尝试将内容类型更改为 text/xml,因为这在另一个页面上对我有用

      【讨论】:

      • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
      • 首先,它没有任何区别(你用我的例子试过了吗?)。其次,我开始相信这是 Firefox 的一个特性,当没有 XSL 样式表时忽略所有标记。
      猜你喜欢
      • 1970-01-01
      • 2011-08-15
      • 2019-01-30
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多