Kisner
Kisner

Reputation: 79

XMLDocument.xml vs XMLDocument.txt

I am looking for clarification here. Is it different to have a .xml file format with XML compared to a .txt document with XML? I would think that if an application expects .xml file, it should be. Am I wrong?

Upvotes: 0

Views: 90

Answers (3)

Tom Blodget
Tom Blodget

Reputation: 20802

From the discussion in comments, it seems like the program is polymorphic, taking a file path for a file of various formats without having an additional argument of which type to expect. It would then have to determine ("guess" or have established rules) what the format is and file extension would be one way.

A different program that only takes an XML file, wouldn't (an IMO, shouldn't) look at the file extension.

Upvotes: 1

Michael Kay
Michael Kay

Reputation: 163352

The file extension .xml or .txt provides a clue as to what might be inside the file, but the clue might be wrong. The extension .xml strongly suggests that the file contains an XML document, while .txt tells you very little apart from the fact that you can probably open it in a text editor and expect to see printable characters.

If an application is going to read the file successfully and make sense of its content then it needs to know far more than that. An application designed to read XML documents containing travel itineraries probably won't understand an XML document containing details of safety inspections at nuclear power stations.

Some intermediate-level applications, however, don't need to understand the file content, they only need to know what low-level manipulations are allowed on the content. For example, if you're transferring files from a Unix machine to an IBM mainframe, should you try to convert from ASCII to EBCDIC? Knowing the file extension or media type can help with that kind of decision - though in the end it's all "best efforts" guesswork.

Upvotes: 1

Quentin
Quentin

Reputation: 943650

Most software only cares about what the content of a file is, not what three letters are at the end of the file name.

The major exceptions are:

  • Software which provides a file picker to pick specific types of files (which often filter based on file extension)
  • Software which decides how to handle a file based on its file extension (such as Windows File Explorer to pick an application to open a file you double clicked on).

On the WWW, the file extension is pretty much irrelevant. When dealing with HTTP, it is the Content-Type HTTP header that matters (for much the same purposes as the file extension is used on a local system). That said, many web servers use the file extension to decide which Content-Type header to use when they serve static files.

Upvotes: 0

Related Questions