XML Documents and XML Files
An XML document contains text, never binary data. It can be opened with any program that knows how to read a text file. Example 2-1 is close to the simplest XML document imaginable. Nonetheless, it is a well-formed XML document. XML parsers can read it and understand it (at least as far as a computer program can be said to understand anything).
<person> Alan Turing </person>
In the most common scenario, this document would be the entire contents of
a file named person.xml, or
perhaps 2-1.xml. However, XML is
not picky about the filename. As far as the parser is concerned, this
file could be called person.txt,
person, or Hey you, there's some XML in this here
file! Your operating system may or may not like these
names, but an XML parser won’t care. The document might not even be in
a file at all. It could be a record or a field in a database. It could
be generated on the fly by a CGI program in response to a browser
query. It could even be stored in more than one file, although that’s
unlikely for such a simple document. If it is served by a web server,
it will probably be assigned the MIME media type application/xml
or text/xml
.
However, specific XML applications may use more specific MIME media types, such as application/mathml+xml
, application/xslt+xml
, image/svg+xml
, text/vnd.wap.wml
, or even text/html
(in very special cases).
Warning
For generic XML documents, application/xml
should be preferred to ...
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.