J.4.1 Understanding the Type of Document

The first step in being able to consume a document is to understand the type of document one will be consuming. Office Open XML supports three primary types of documents: documents, presentations and spreadsheets. The type of document is determined programmatically by looking at the content type of the start part.

The first step is getting the content type is to identify the target part of the ‘officedocument’ relationship. To do this, one needs to start in the /_rels/.rels file and identify the relationship of type http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument:

<Relationships
xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId3"
Type="http://purl.oclc.org/ooxml/officeDocument/relationships/extendedPrope
rties"
    Target="docProps/app.xml"/>
  <Relationship Id="rId2"
Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata
/core-properties"
    Target="docProps/core.xml"/>
  <Relationship Id="rId1"
Type="http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocumen
t"
    Target="word/document.xml"/>
</Relationships>

Then, given the target of that relationship, in this case “word/document.xml,” the [Content_Types].xml file is used to look up the content type for this target. Given the following [Content_Types].xml file,

<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-
types">
  <Default Extension="rels" ContentType="application/vnd.openxmlformats-
package.relationships+xml"/>
  <Default Extension="xml" ContentType="application/xml"/>
  <Override PartName="/word/document.xml"
    ContentType="application/vnd.openxmlformats-
officedocument.wordprocessingml.document.main+xml"/>
  <Override PartName="/word/styles.xml"
    ContentType="application/vnd.openxmlformats-
officedocument.wordprocessingml.styles+xml"/>
  <Override PartName="/docProps/app.xml"
    ContentType="application/vnd.openxmlformats-officedocument.extended-
properties+xml"/>
  <Override PartName="/word/settings.xml"
    ContentType="application/vnd.openxmlformats-
officedocument.wordprocessingml.settings+xml"/>
  <Override PartName="/word/theme/theme1.xml"
    ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
  <Override PartName="/word/fontTable.xml"
    ContentType="application/vnd.openxmlformats-
officedocument.wordprocessingml.fontTable+xml"/>
  <Override PartName="/word/webSettings.xml"
    ContentType="application/vnd.openxmlformats-
officedocument.wordprocessingml.webSettings+xml"/>
  <Override PartName="/docProps/core.xml"
    ContentType="application/vnd.openxmlformats-package.core-
properties+xml"/>
</Types>

The content type is application/vnd.openxmlformats- officedocument.wordprocessingml.document.main+xml, which tells us that the file is a document file.

Last updated on