Go to main content

Oracle® Solaris 11.3 Desktop Administrator's Guide

Exit Print View

Updated: March 2018
 
 

Understanding MIME Type XML Files

    The MIME XML files provide all the information regarding MIME types that are installed into the MIME database by the update-mime-database application. The MIME XML files are located in the <MIME>/packages directory. A few rules about the MIME XML files:

  • The XML file must specify the namespace as https://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).

The following table gives a brief description of each element that can occur as children to the mime-type element.

Table 6  Child elements of <mime-type>
Element (and attributes)
Description
<glob pattern="*.xyz">
This element specifies a glob pattern for the filenames. If the filename matches, then the file 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 and an optional attribute:
  • type

  • offset

  • value

  • mask (optional attribute)

For details about these attributes, see the XDG shared mime info specification.
<alias type="media/subtype">
This element defines an alias for the parent mime-type element. For example, application/x-pdf is an alias for the application/pdf MIME type.
<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 subclass of the text/xml, text/plain, and application/octet-stream MIME types.
<comment xml:lang="locale">
This element provides a 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 be an XML file, then this element helps to further classify the file type by using the namespaceURI and localName attributes. The namespaceURI attribute is the namespace of the document, and localName is the name of the root element for the document. If localName is present but the value is empty, then the root element might have any name but the namespace must still match.

The following example defines the text/x-diff MIME type.

Example 3  Example of a diff.xml source XML file:
<?xml version='1.0'?>
<mime-info xmlns='https://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>

In this example, multiple comment elements give a readable name to the MIME type in a number of different languages. The text/x-diff MIME type has rules for matching both through glob patterns and through the use of content sniffing (known as magic rules). Any file with the .diff or .patch extension 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. For more details about the glob patterns and magic rules, see the XDG shared mime info specification.