英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论