DocumentID: ECMA-376/Part2/9.1.2 Title: ECMA-376, Part2: 9.1.2 Mapping Content Types Extracted-From: ECMA-376 Office Open XML File Formats, 1st Edition / December 2006 Warning: Coverted to HTML format by a script known to have bugs
Methods for mapping part content types to a physical format are described below.
The package implementer shall define a format mapping with a mechanism for associating content types with parts. [M2.3]
Some physical package formats have a native mechanism for representing content types. [Example: the content type header in MIME end example] For such packages, the package implementer should use the native mechanism to map the content type for a part. [S2.1]
For all other physical package formats, the package implementer should include a specially-named XML stream in the package called the Content Types stream. [S2.2] The Content Types stream shall not be mapped to a part by the package implementer. [M2.1] This stream is therefore not URI-addressable. However, it can be interleaved in the physical package using the same mechanisms used for interleaving parts.
The Content Types stream identifies the content type for each package part. The Content Types stream contains XML with a top-level Types element, and one or more Default and Override child elements. Default elements define default mappings from the extensions of part names to content types. Override elements are used to specify content types on parts that are not covered by, or are not consistent with, the default mappings. Package producers can use pre-defined Default elements to reduce the number of Override elements on a part, but are not required to do so. [O2.4]
The package implementer shall require that the Content Types stream contain one of the following for every part in the package:
The package implementer shall require that there not be more than one Default element for any given extension, and there not be more than one Override element for any given part name. [M2.5]
The order of Default and Override elements in the Content Types stream is not significant.
If the package is intended for streaming consumption:
[S2.3]
The package implementer can define Default content type mappings even though no parts use them. [O2.5]
The structure of a Types element is shown in the following diagram:
|
diagram |
|
|
|
annotation |
|
The structure of a Default element is shown in the following diagram:
|
diagram |
|
||||||||||||||||||||
|
attributes |
|
||||||||||||||||||||
|
annotation |
|
The structure of an Override element is shown in the following diagram:
|
diagram |
|
||||||||||||||||||||
|
attributes |
|
||||||||||||||||||||
|
annotation |
|
[Example:
Example 9--7. Content Types stream markup
<Types
xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="txt" ContentType="text/plain" />
<Default Extension="jpeg" ContentType="image/jpeg" />
<Default Extension="picture" ContentType="image/gif" />
<Override PartName="/a/b/sample4.picture" ContentType="image/jpeg" />
</Types>
The following is a sample list of parts and their corresponding content types as defined by the Content Types stream markup above.
|
Part name |
Content type |
|---|---|
|
/a/b/sample1.txt |
text/plain |
|
/a/b/sample2.jpg |
image/jpeg |
|
/a/b/sample3.picture |
image/gif |
|
/a/b/sample4.picture |
image/jpeg |
end example]
When adding a new part to a package, the package implementer shall ensure that a content type for that part is specified in the Content Types stream; the package implementer shall perform the following steps to do so [M2.8]:
Extension attributes of the Default elements in the Content Types stream. The comparison shall be case-insensitive ASCII.Extension attribute, then the content type of the new part shall be compared with the value of the ContentType attribute. The comparison might be case-sensitive and include every character regardless of the role it plays in the content-type grammar of RFC 2616, or it might follow the grammar of RFC 2616. To get the content type of a part, the package implementer shall perform the following steps [M2.9]:
PartName attribute of the Override elements. The comparison shall be case-insensitive ASCII. PartName attribute, return the value of its ContentType attribute. No further action is required. PartName attribute, then Extension attribute. The comparison shall be case-insensitive ASCII.Extension attribute, return the value of its ContentType attribute. No further action is required. The package implementer shall not use the versioning and extensibility mechanisms defined in Part 5: "Markup Compatibility and Extensibility" to incorporate elements and attributes drawn from other XML-namespaces into the Content Types stream markup. [M2.10]