Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

The source XML files

Located in the <MIME>/packages directory, these XML files provide all the information regarding MIME types that is installed into the database by the update-mime-database application. There are a few rules about the XML file itself:

  • It must specify the namespace as “http://www.freedesktop.org/standards/shared-mime-info

  • The root element must be mime-info

  • Zero or more mime-type elements can be specified as children of the mime-info element. The type attribute is used to specify the MIME type that is being defined.

By default, the freedesktop.org.xml file is installed to the packages directory in one of the <MIME> paths (usually /usr/share/mime/packages).

Table 5.1, “Child elements of <mime-info>” gives a brief description for each of the elements that can occur as children to the mime-type element.

Table 5.1. Child elements of <mime-info>

Element (and attributes) Description
<glob pattern="*.xyz"> This element specifies a glob pattern against filenames. If the filename matches, then it is assigned the MIME type of the parent mime-type element. The pattern attribute is mandatory.
<magic priority="50"> This element contains a list of match elements as its children. The priority attribute is optional, and specifies a priority between 0 and 100, with 100 being the highest matching priority. Each child match element has three required attributes: type, offset, value and a fourth optional attribute, mask. For details on these attributes, see the XDG shared mime info specification.
<alias type="media/subtype"> This element defines an alias for the parent mime-type element. An alias is simply a MIME type that is sometimes known as another type. For example, application/x-pdf is an alias for the MIME type application/pdf.
<sub-class-of type="media/subtype"> This element defines the parent mime-type element as a subclass of the MIME type specified in the type attribute. For example, image/svg is a sub class of the MIME type text/xml, text/plain, and application/octet-stream.
<comment xml:lang="locale"> This element provides a human readable description for the MIME type. There can be zero or more occurrences of this element as long as each one contains a unique value for the xml:lang attribute.
<root-XML namespaceURI="namespace" localName=""> If a file is determined to an XML file, then this element helps to further classify it through the use of the namespaceURI and localName attributes, both of which are required. The attribute namespaceURI is the namespace of the document, and localName is the name of the root element for the document. If localName is present but its value is empty, then the root element may have any name, but the namespace must still match.

The easiest way to understand these files is to take a look at an example. Borrowing from the XDG shared mime specification, Example 5.2, “Example of a source XML file: diff.xml” displays the contents of a source XML file called diff.xml. This example defines the MIME type text/x-diff. There are multiple comment elements which give a human readable name to the MIME type in a number of different languages. This MIME type has both rules for matching through glob patterns and through the use of content “sniffing” (better known as magic rules). Any file with the extension .diff or .patch will resolve to this MIME type. Additionally any file whose contents start with the strings specified in the value attributes of the match element, will resolve to the text/x-diff MIME type.

The order in which glob patterns and magic rules apply is beyond the scope of this document. For details on this, see the XDG shared mime info specification.

Example 5.2. Example of a source XML file: diff.xml

<?xml version='1.0'?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="text/x-diff">
    <comment>Differences between files</comment>
    <comment xml:lang="af">verskille tussen lêers</comment>
    <!-- more translated comment elements -->
    <magic priority="50">
      <match type="string" offset="0" value="diff\t"/>
      <match type="string" offset="0" value="***\t"/>
      <match type="string" offset="0" value="Common subdirectories: "/>
    </magic>
    <glob pattern="*.diff"/>
    <glob pattern="*.patch"/>
  </mime-type>
</mime-info>

Previous
The MIME Database
GNOME 2.14 Desktop System Administration Guide Next
Modifying MIME types

 
 
  Published under the terms of the GNU General Public License Design by Interspire