Open Packaging Conventions - Package, Parts, and Relationships

Package, Parts, and Relationships

In OPC terminology, the term package corresponds to a ZIP archive and the term part corresponds to a file stored within the ZIP. Every part in a package has a unique URI-compliant part name along with a specified content-type expressed in the form of a MIME media type. A part's content-type explicitly defines the type of data stored in the part, and reduces duplication and ambiguity issues inherent with file extensions.

OPC packages can also include relationships that define associations between the package, parts, and external resources. In addition to a hierarchy of directories and parts, OPC packages commonly use relationships to access content through a directed graph of relationship associations. Relationships are composed of four elements:

  • an identifier (ID)
  • an optional source (the package or a part within the package)
  • a relationship type (a URI-style expression that defines the type of the relationship)
  • a target (a URI to another part within the package or to an external resource)

OPC packages can store parts that contain any type of data (text, images, XML, binary, whatever). The extension ".rels", however, is reserved for storing relationships metadata within "/_rels" subfolders. The subfolder name "_rels", the file extension ".rels" within such directory, and the filename ".xml" in any folder are the only three reserved names for files stored in an OPC package.

/.xml file
This file defines the MIME media types for all the parts stored in the package. The "/.xml" file defines default mappings based on file extensions, along with overrides for specific parts with content-types that are different from the file extension defaults. For example, one of these defined MIME types is:
/_rels
The root level "/_rels" folder stores the relationships for the package as a whole. The "/_rels" folder normally contains a file named ".rels". "/_rels/.rels" is an XML file where the starting package-level relationships are stored. Normally when opening an OPC-based file, applications start by accessing to the "/_rels/.rels" file to read the starting package-level relationships.
.rels
Each part may have its own relationships. The_rels folders are where one goes to find the relationships for any given part within the package. To find the relationships for a specific part, one looks in the "_rels" folder that is a sibling of that part: If the part has relationships, the "_rels" folder will contain a file that has one's original part name with a ".rels" appended to it. For example, if the content types part file had any relationships, there would be a file called ".xml.rels" inside the "/_rels" folder.

All relationships (including the relations associated to the root package) are represented as XML files. If you open a ".rels" file in a text editor, you can view the actual XML markup that defines all the relationships targeted from that part. A typical relationships file contains XML code like this:

which defines two relations for the root package, the first one being considered as the root package (here for an early Microsoft XPS document, before it was standardized as Open XML Paper Specification within the openxmlformats collection), and the other one being used to reference an alternate form (here a thumbnail rendered image of the first page of the document).

The main parts of the embedded documents are often stored within a folder named "/Document" (which may contain subdirectories itself, if the file contains several related documents each of them with various parts), and the optional metadata parts that are not needed for processing the main parts of the document are stored in a folder named "/Metadata" ; however these actual folder names are actually specified within the XML-formatted data in ".rels" relationship files, and the OPC specification allows any folder organisation that is convenient for the application and these two folder names are not required.

Read more about this topic:  Open Packaging Conventions