0

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?

alex.jordan
  • 296
  • 2
  • 11
  • Firefox is able to open an xml file without extension as XML. Use web developer console to inspect the tree. The server should send `Content-Type application/xml` header or equivalent – LMC Jun 29 '23 at 02:50
  • @LMC Do you mean something more than the DOM inspector? I don't want to see the artificial DOM elements the browser creates, nor whatever patching it tries to do to broken XML. – alex.jordan Jun 29 '23 at 03:04
  • Also I would like a solution that does not ask a user to use the developer console, if possible. I suspect that I may be out of luck. But I'm hoping there is a way to make it so the browser just shows the xml tree, like for example here: https://www.w3schools.com/xml/note.xml. – alex.jordan Jun 29 '23 at 03:07
  • The server should send `Content-Type application/xml` header or equivalent – LMC Jun 29 '23 at 04:10
  • 1
    @LMC Thanks, that is the push that I needed. If you post as an answer, I can mark it accepted. It really does answer the question I had. – alex.jordan Jun 30 '23 at 18:41

1 Answers1

1

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

For differences between the 2 see this answer.

LMC
  • 10,453
  • 2
  • 27
  • 52