在web浏览器中的XML,即使没有 .xml 后缀

huangapple go评论56阅读模式
英文:

XML in web browser, even without .xml extension

问题

我有一个服务页面的应用程序,该页面返回XML(如果“页面”是正确的术语的话)。例如,页面源代码可能如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <foo>bar</foo>
</root>

我想能够打开Web浏览器并将页面显示为XML(带有可折叠树、识别无效XML等功能),这通常是Web浏览器所做的。然而,似乎如果URL路径末尾没有“.xml”扩展名,浏览器就不愿这样做。尽管顶行有XML声明。

在服务器级别上有什么我可以做的吗?

英文:

I have an application that serves a page of XML (if "page" is even the right term). For example, the page source might look like:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <foo>bar</foo>
</root>

I would like to be able to open a web browser and view the page as XML (with collapsible tree, recognition of invalid XML, etc), which web browsers generally do. However it seems that without a .xml extension at the end of the URL path, the browsers are unwilling to do this. In spite of the xml declaration at the top line.

Is there anything I can do at the server level to make it work the way I'd like?

答案1

得分: 1

服务器应发送Content-Type: application/xml头部或等效头部。 text/xml也应该可以。

关于两者之间的区别,请参阅此答案

英文:

The server should send Content-Type: application/xml header or equivalent.
text/xml should also work.

For differences between the 2 see this answer.

huangapple
  • 本文由 发表于 2023年6月29日 10:37:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577748.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定