Does it matter if my XML file has an extension other than .xml?

568 views Asked by At

I'm developing a project that will use XML files to dump data for sharing between servers. Does it matter if I use an extension other than .xml in the file name? eg. 'myfile.abc' instead of 'myfile.xml'.

These files would be read by client servers using CURL / LWP commands. Are there any issues with MIME-TYPES that might cause the files to be unopenable or unreadable as XML? (They will be W3C compliant XML files)

The reason is we need the files to be distinguishable from other XML files on the server. Thanks.

3

There are 3 answers

4
kjhughes On

The W3C XML Recommendation specifies nothing about an XML file's name or extension.

However, an application or operating system may rely on a file extension to identify file content type. There's also no guarantee how any given application would interpret conflicting signals from a file's MIME type and its file extension.

Recommendation: Stick with the conventional .xml file extension for XML files. To make "the files to be distinguishable from other XML files on the server," use a suitable naming convention on the base file name instead.

1
Misunderstood On

You would need to configure your server to use the MIME type application/xml or text/xml for an .abc extension.

I just configured my server to consider a .abc to be a text/xml file.

enter image description here

2
Michael Kay On

This applies to file extensions generally, not just the .xml extension.

The most common cases where file extensions are used are:

(a) when you double-click on a file in a graphical file explorer/finder, the operating system decides what application to open based on the file extension. You can configure the mapping from file extensions to applications, so you don't have to use ".xml", you can use any extension that's mapped to the appropriate application.

(b) when a web server delivers content in response to an HTTP request, the response contains the content type (media type / MIME type) and this will often be based on the file extension. This information is used by the browser when deciding how to display the content. Again, you can configure the mapping of file extensions to media types in the configuration files of your web server (e.g. Apache).

It's quite normal to use particular file extensions for particular XML vocabularies, e.g. .xsl for XSLT and .xsd for XML Schema. But it will work best if you ensure such extensions are properly configured.