XML and MIME
Encyclopedia : X : XM : XML : XML and MIME
- 1 A Summary of XML and Media Types (MIME)
- 2 Where are MIME Types Used?
- 3 XML does not \"have\" a MIME Type!
- 4 What is the Purpose of a MIME Type?
- 5 How does Data get Assigned a MIME Type?
- 6 Can Data be Assigned a Wrong MIME Type?
- 7 Browsers use MIME Type to Decide how to Render a Resource
- 8 Beyond MIME Types?
- 9 What is an XML Document?
- 10 Further Information
A Summary of XML and Media Types (MIME)
You can find a list of over 350 different (Multipurpose Internet Mail Extensions) MIME types here: [MIME Types]
From this list, you can see that there are two MIME assignments for (Extensible Markup Language ) XML data. These are:
- application/xml
- text/xml
- application/xml
- type/subtype
- application/xsl+xml
- image/svg+xml
NOTE: The format for expressing MIME types use specific XML vocabulary:
- type/___+xml
Where are MIME Types Used?
MIME (Multipurpose Internet Mail Extensions) is a way of informing applications on the nature of the data contained within a file or a message and is used in the exchange of information on the Web.
Application:
Suppose you send data to a Web server. The data will arrive as a stream of bytes with no filename or file extension, (".xml"). How does the Web server determine what bytes represent XML data and differentiate it from other kinds of data?
Answer: Data sent across the Web is sent as a payload in an HTTP message. Embedded in the HTTP header is a field called, Content-type where the value of this field is a MIME type.
e.g.
Content-type: application/xmlNow, when the Web server receives the stream of bytes, it will examine the Content-type header field to determine the type of data present.
This process can then be reversed and applied to Web servers sending data out. The Web server assigns a MIME type to the data being transmitted via the same process (using the Content-type header).
When a Web browser receives data (also known as a stream of bytes) from the Web, it looks at the MIME type in Content-type to determine how to render the data.
In Summary:
MIME types were created for networks. Their purpose is to inform network applications (such as Web servers and browsers) of the nature of the data being sent and received.
XML does not \"have\" a MIME Type!
It is misleading to say that XML has a MIME type of application/xml. The statement suggests that the MIME type is somehow part of - or a property of an XML document.
Which is not true.
An XML document does not have a MIME property - instead, a stream of bytes may be assigned the MIME type application/xml.
The MIME type is therefore an externally applied label, similar in many ways to a file type extension (such as, “.xml”, “.txt”) but not as persistent. In other words, it is pure metadata!
What is the Purpose of a MIME Type?
The purpose of a MIME type is to provide network applications such as Web browsers and Web servers with information about the type of data they have received.
With this information, a Web browser or Web server can trigger an appropriate program to handle this received data.
How does Data get Assigned a MIME Type?
Application:
Suppose a Web server is invoked where the data that it is to be returned is located in a file somewhere on its local file system. The Web server reads the file's data and constructs an HTTP message. How does it assign an appropriate MIME type to the data? (How does it fill in the Content-type field?)
Answer: Heuristics are used for determining the MIME type of a resource. Put simply, the Web server guesses what the MIME type is and the heuristics used depends on the operating system (or platform).
On Windows, the MIME type is guessed from the file extension where in the Window’s Registry there is a mapping from a file extension to the MIME type.
Examples:
- If a file ends with the extension .txt then the MIME type is guessed to be text/plain.
- If a file ends with the extension .doc then the MIME type is guessed to be application/msword.
- If a file ends with the extension .xml then the MIME type is guessed to be application/xml.
- If a file ends with the extension .zip then the MIME type is guessed to be application/zip.
In Summary:
We see that MIME type provides information about the format of data, independent of platform!
Can Data be Assigned a Wrong MIME Type?
Yes!
It is possible to create a Word document and deliberately give the document a false extension such as ".xml". If the Web server is running on a Windows machine, then the Web server will assign a MIME type of application/xml to the data - which is clearly incorrect.
Browsers use MIME Type to Decide how to Render a Resource
With the exception of Internet Explorer, browsers use MIME type to decide how to render a resource. If the resource is retrieved from the Web, then the MIME type is found in the HTTP header. If the resource comes from a file on the local file system then the MIME type is guessed using heuristics, as described above.
Internet Explorer uses the MIME type found in the HTTP header to determine how to render a resource retrieved from the Web. However, for resources that come from the local file system, Internet Explorer uses the file extension to determine how to render the resource.
Beyond MIME Types?
MIME types may be criticized for not capturing some important metadata. For example, suppose that a Web server receives some data, and in the Content-type header it shows this MIME type:
Content-type: application/mswordThe MIME type tells the Web server that the data is Word data. However, which version of Word is the data? The MIME type doesn't differentiate.
What is an XML Document?
Application:
Take this simple XML:
Put it into Word and deliberately give the document the incorrect extension “.xml”. Name the file “Blah.xml”. Now make this file Web-accessible. Next, suppose someone on the Web requests the file by issuing its URL, e.g.,Blah
http://www.example.org/Blah.xmlThe Web server will read in the data from the file, and assign a MIME type to it. Let’s assume the Web server is running on a Windows machine; then the Web server will use the file extension to assign a MIME type. Here’s the MIME type it will assign to the data:
application/xmlHowever, the data is not XML, but it is Word.
Conversely, take the same XML and put it into Notepad and give the document the extension “.txt”. Name the file “Blah.txt”. Also make this file Web-accessible. Next, suppose someone on the Web requests the file by issuing its URL, e.g.,
http://www.example.org/Blah.txtThe Web server will read in the data from the file, and assign a MIME type to it. Let’s assume the Web server is running on a Windows machine; then the Web server will use the file extension to assign a MIME type. Here’s the MIME type it will assign to the data:
text/plainEven though it is an XML document.
So, what is an XML document?
Answer: an XML document is one that may or may not have an XML declaration and is followed by a root element with well-formed content.
If you open the above Word document you won’t find an XML declaration or a root element. If you open the above Notepad document you will find an XML declaration as the first option.
Further Information
Elliotte Rusty Harold has written an excellent [article] on this subject.
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
