开发者

google chrome - opening an xml file via hyperlink show xml as regular text

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 exampl开发者_如何学编程e: 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


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.

google chrome - opening an xml file via hyperlink show xml as regular text

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.

google chrome - opening an xml file via hyperlink show xml as regular text

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 vse...@chromium.org, May 3, 2011 
The target="_blank" problem is already fixed in Chrome 12.

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


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?


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;}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜