[
Lists Home |
Date Index |
Thread Index
]
It isn't the editor that determines its mime type, but the systems
(browsers, servers, other applications) which are sending and receiving
the resource which must either take the word of another system, or
themselves make an inference based on the actual content they see or
some other properties associated with the resource (usually the file
name). Elliotte's article mentions these mechanisms.
What an editor _does_ determine, is the data written inside the file.
So, in the case of Word, it is not really writing XML but DOC format.
What complicates things is that DOC is a compound document format, and
can embed XML data inside of it, or merely represent it as a series of
paragraphs and spans of styled text which only appears to be XML on the
surface. But even if it embeds islands of XML within, or even if you
used the DOCX serialization, the file format itself is most definitely
not your XML.
If Notepad is left to its default dialog settings, it will append a
".txt" on the file name, which then results in IE6, and at least one
Java-based XML editor I use, inferring the media type as plain text. The
IE6 inference is based on a mapping ".txt -> mime type text/plain" in
the Windows Registry. So in the case of Windows, the answer you are
looking for - how does an application decide what mime type to use - the
answer is that the file extension is mapped to a mime type in the
Registry. Note that this has nothing at all to do with the actual
content of the file. Web servers provide their own similar mapping
mechanisms.
Costello, Roger L. wrote:
>
> Hi Folks,
>
> Below I have summarized our discussion on XML and media types (MIME).
> Please let me know if there are any inaccuracies in the summary. /Roger
>
> *A Summary of XML and Media Types (MIME)*
>
> *What is XML’s MIME Type?*
>
> At this URL is a list of the 350 different MIME types:
>
> http://www.iana.org/assignments/media-types/
>
> In this list you will see two different MIME types for XML:
>
> *application/xml*
>
> * text/xml*
>
> The later MIME type (*text/xml*) has been deprecated. Thus, the
> official MIME type for XML is:
>
> *application/xml*
>
> Note the format for expressing MIME types – it contains two parts,
> separated by a slash:
>
> / *type*/*//subtype/*
>
> *The Editor used to Create the XML Determines its MIME Type*
>
> Interestingly, you may have a document which contains XML and yet its
> MIME type may not be *application/xml*.
>
> For example, take this simple XML:
>
> *<?xml version="1.0"?>*
>
> *<root>*
>
> * Blah*
>
> *</root>*
>
> and put it into *Word* (save it as a .doc file). The MIME type is:
>
> *application/msword*
>
> Conversely, if you put the same XML into *Notepad*, the MIME type is:
>
> *application/xml *
>
> Why is that? Why is it that if you put XML into one editor (*Word*)
> you get a MIME type that is specific to the editor, whereas if you put
> XML into another editor (*Notepad*) you get a MIME type that is
> independent of the editor?
>
> The answer is this: when the XML is put into *Word*, the *Word*
> application wraps the XML with a bunch of *Word*-specific stuff (the
> wrapper stuff is not visible). Consequently, the *Word* document isn't
> something you can feed directly into an XML parser.
>
> Conversely, *Notepad* does not wrap the XML with anything. The
> document is pure XML, it can be fed directly into an XML parser, and
> thus it has a MIME type of *application/xml*.
>
> Suppose that you put the XML into *Wordpad*, what is its MIME type?
>
> Answer: it depends on how you save the file. If you save it as a text
> document (SaveAs = Text Document) then the MIME type will be
> *application/xml*. If you save it as Rich Text (SaveAs = Rich Text)
> then the editor will wrap the XML in some stuff, and the MIME type
> will be different – it will be *text/richtext*.
>
> Lastly, suppose that you put the XML into *Notepad* and then compress
> it using *Winzip*, what is its MIME type?
>
> Answer: *application/zip*
>
> *Further Information*
>
> Elliotte Rusty Harold has written an excellent article on this subject:
>
> http://www-128.ibm.com/developerworks/xml/library/x-mxd2.html
>
> *Acknowledgements*
>
> I would like to gratefully acknowledge the excellent inputs from these
> people:
>
> Mitch Amiano
>
> Dave Pawson
>
> Bryan Rasmussen
>
> Henri Sivonen
>
|