Mac OS X Reference Library Apple Developer
Search

Spotlight Importer Schema Format

For Spotlight to know what attributes an importer supports, it must provide a schema file. The schema file describes the attributes that the importer populates, describes the attributes that applications should use to provide a preview of the document’s metadata, and specifies any custom metadata attributes that your documents require.

The Schema.xml File

The schema is specified in an XML schema file called schema.xml within your Spotlight importer bundle.

The following XML fragment shows the general format of the file.

<?xml version="1.0" encoding="UTF-8"?>
<schema version="1.0" xmlns="http://www.apple.com/metadata"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://www.apple.com/metadata
file:///System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/
Resources/MetadataSchema.xsd">
    <attributes>
    ...
   </attributes>
    <types>
        <type name="SUPPORTED_UTI_TYPE">
            <allattrs>
        ...
            </allattrs>
            <displayattrs>
        ...
            </displayattrs>
        </type>
    </types>
</schema>

Specifying Custom Attributes

Custom attributes for your Spotlight importer are declared as attribute elements that are children of the attributes element. The XML attributes for the attribute element are shown in Table 1.

Table 1  Attributes of attribute element

Attributes

Description

name

The name of the custom metadata attribute. The metadata attributes are prefixed with the reverse DNS naming schema, replacing “.” with “_” for key-value coding compatibility.

type

The data type that the attribute returns. Only the following CF types are supported: CFString, CFNumber, CFBoolean and CFDate.

multivalued

If the importer returns an array of values for this metadata attribute this attribute should be “true”. If this attribute is omitted, “false” is assumed.

uniqued

If the importer returns only a small number of possible values for an attribute, space in the system store can be saved by setting this attribute to “true”. If this attribute is omitted, “false” is assumed. This attribute is optional, and should only be specified when there is a very small number of values possible for the attribute.

nosearch

If set to “true” this attribute is only searched when it is specifically declared as a target metadata attribute in the search string. If this attribute is omitted, “false” is assumed and all wildcard attribute searches will include the values of this metadata attribute.

The following is an example XML fragment for the attributes element of a schema.

<attributes>
    <attribute name="com_apple_myCocoaDocumentApp_myCustomDocument_notes" multivalued="false" type="CFString"/>
</attributes>

Specifying the Attributes for a Document

There is a single type element for each document type that your importer can read. The XML attributes for the type element are shown in Table 2.

Table 2  Attributes of type element

Attributes

Description

name

The Uniform Type Identifier declared for the document type.

A type element specifies the metadata attributes that it returns in the allattrs element, separating each name with whitespace. The allattrs element should contain all the elements related to your custom document.

The metadata attributes to be displayed for previewing for a document—for example in Finder’s Get Info panel—are listed within the displayattrs element, separating each name with whitespace.

The following is an example XML fragment for a types element of a schema.

<types>
    <type name="com.apple.mycocoadocumentapp.mycustomdocument">
        <allattrs>
            com_apple_myCocoaDocumentApp_myCustomDocument_notes
        </allattrs>
        <displayattrs>
            com_apple_myCocoaDocumentApp_myCustomDocument_notes
        </displayattrs>
    </type>
</types>



Last updated: 2009-10-11

Did this document help you? Yes It's good, but... Not helpful...