google chrome - 通过超链接打开 xml 文件将 xml 显示为常规文本

发布于 2024-11-06 15:11:25 字数 818 浏览 0 评论 0 原文

我想在 iframe 中显示 xml 文件。 它在 Firefox 和 IE 中工作正常,但在 chrome 中将 xml 显示为文本。

所以我想检查一下这是否是一个普遍问题。 例如: 如果我使用位于 查看 XML 食物菜单 链接http://www.w3schools.com/xml/xml_examples.asp" rel="nofollow">http://www.w3schools.com/xml/xml_examples.asp 然后我得到显示为文本的 xml文件。

如果我右键单击该链接并选择在新选项卡中打开,它将显示应有的 xml。 或者如果我打开一个新选项卡并输入网址 http://www.w3schools.com/xml/ simple.xml 它将文件显示为 xml 文件。

如果您按鼠标右键并选择“在新选项卡中打开”,它将按预期显示 xml。

我认为无论什么原因导致这个问题都会导致我面临的问题。 所以我的问题是:

  1. 是什么原因造成的?
  2. 有办法解决这个问题吗?
  3. 这是 Chrome 中的错误吗?

谢谢。

chrome 版本是 11.0.696.65

操作系统:windows xp,我也在 windows 7 中检查过这个

i want to show an xml file inside an iframe.
it works fine in firefox and ie but in chrome show the xml as text.

so i wanted to check if this is a general problem.
for example:
if i use the View an XML food menu link that is located in http://www.w3schools.com/xml/xml_examples.asp then i get the xml shown as a text file.

if i right click the link and chose open in new tab it will show the xml as it should.
or if i open a new tab and put the url http://www.w3schools.com/xml/simple.xml it shows the file as an xml file.

if you press the right mouse button and select "open in a new tab" it will show the xml as it should.

i think that whatever causes this problem causes the problem i am facing.
so my questions are:

  1. what causes this ?
  2. is there a way around this problem ?
  3. is this a bug in chrome ?

thanks.

chrome version is 11.0.696.65

OS: windows xp,i have also checked this in windows 7

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深者入戏 2024-11-13 15:11:25

对我来说,这绝对是 Google Chrome 的错误。尝试右键单击该链接并选择“在新选项卡中打开链接”或“在新窗口中打开链接”以查看漂亮的打印 XML。

在此处输入图像描述

锚元素中有 target="_blank" 属性,这会导致问题:

<a target="_blank" href="simple.xml">View an XML food menu</a>

查看另一个网站 http://www.xmlfiles.com/examples/。没有 target="_blank" 并且链接效果很好。

您可以使用“检查元素→编辑为 HTML”选项来删除该属性 target="_blank",之后 XML 也可以很好地打印。

在此处输入图像描述

我终于找到了 Chromium 问题 84128(2011 年 5 月 26 日报告,版本11.0.696.71)为此。

您不需要添加任何明确的 XSLT 样式表。这里的情况根本不是这样。如果没有应用样式表,则浏览器会隐式使用其内置的默认变体。

编辑:

我下载了Google Chrome 12 beta(版本12.0.742.77 beta-m)beta-m,这里错误已解决

Comment 93 by project member [email protected], May 3, 2011 
The target="_blank" problem is already fixed in Chrome 12.

(来自 http://code.google.com/p/chromium/问题/详细信息?id=434

For me this is definitely Google Chrome bug. Try to use right-click on that link and select "Open link in new tab" or "Open link in new window" to see pretty printed XML.

enter image description here

There is target="_blank" attribute within anchor element, which causes that problem:

<a target="_blank" href="simple.xml">View an XML food menu</a>

Look at another site http://www.xmlfiles.com/examples/. There is no target="_blank" and links works well.

You can use Inspect Element → Edit as HTML option to remove that attribute target="_blank" and after that XML is printed well too.

enter image description here

Finally I found Chromium Issue 84128 (reported 26/5/2011, version 11.0.696.71) for that.

You don't need to add any explicite XSLT stylesheet. That's simply not the case here. If there is no stylesheet applied, then browser implicitly uses their built-in, default variant.

Edit:

I downloaded Google Chrome 12 beta (version 12.0.742.77 beta-m) beta-m and here this bug is solved.

Comment 93 by project member [email protected], May 3, 2011 
The target="_blank" problem is already fixed in Chrome 12.

(from http://code.google.com/p/chromium/issues/detail?id=434)

玩套路吗 2024-11-13 15:11:25

我认为问题在于 xml 没有引用样式表。 xml 引用样式表的其他链接第一次可以正常打开。也许添加一个最小的样式表就能解决你的问题?

I think the problem is that the xml does not reference a stylesheet. The other links where the xml does reference a stylesheet open fine the first time. Maybe adding a minimal stylesheet will fix the problem for you?

眉目亦如画i 2024-11-13 15:11:25

据我所知,Chrome 没有 bug。 Chrome 不会对 XML 文档应用任何样式。

要解决此问题,请将样式表添加到您的 XML 文件中,如下所示

<?xml-stylesheet type="text/css" href="/Styles/olg_rss.css" ?>

它应该出现在版本 + 编码之后

<?xml version="1.0" encoding="ISO-8859-1" ?>

这是我创建的一个 stylesheet

rss {font-family:Arial, Helvetica, sans-serif;}

channel title {display:block; 
    padding:1em; color:#FFF; border-bottom:1px solid black; 
    font-weight:bold;
    font-size:140%; background-color:#4483C7;}

channel description {display:block; float:left; 
    font-size:130%; margin:1em;}

channel item {border:1px solid #4483c7;clear:both; 
    display:block; padding:0.5em; margin:1em;}

channel item title {background-color:#4483c7; 
    border-bottom-width:0; color:#FFF; display:block; 
    font-size:110%; font-weight:bold; margin:0; padding:0.2em;}

channel item description {display: block; float:none; 
    margin:0; text-align: left; padding:0.2em 0.5em 0.4em; 
    color: black; font-size:100%; font-weight:normal;}

channel item link {color:#666; display:block; font-size:86%; 
    padding:0 0.5em;}

As far as I know, there is no Chrome bug. Chrome just does not apply any styling to XML docs.

To fix this, add a stylesheets to your XML file, like so

<?xml-stylesheet type="text/css" href="/Styles/olg_rss.css" ?>

It should appear after the version + encoding

<?xml version="1.0" encoding="ISO-8859-1" ?>

This is one stylesheet I've created.

rss {font-family:Arial, Helvetica, sans-serif;}

channel title {display:block; 
    padding:1em; color:#FFF; border-bottom:1px solid black; 
    font-weight:bold;
    font-size:140%; background-color:#4483C7;}

channel description {display:block; float:left; 
    font-size:130%; margin:1em;}

channel item {border:1px solid #4483c7;clear:both; 
    display:block; padding:0.5em; margin:1em;}

channel item title {background-color:#4483c7; 
    border-bottom-width:0; color:#FFF; display:block; 
    font-size:110%; font-weight:bold; margin:0; padding:0.2em;}

channel item description {display: block; float:none; 
    margin:0; text-align: left; padding:0.2em 0.5em 0.4em; 
    color: black; font-size:100%; font-weight:normal;}

channel item link {color:#666; display:block; font-size:86%; 
    padding:0 0.5em;}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文