Relationships in Office Open XML

In OPC, relationships describe references from parts to other internal resources in the package or to external resources. They represent the type of connection between a source part and a target resource, and make the connection directly discoverable without looking at the part contents, so they are quick to resolve.

The same ZIP item can be the target of multiple relationships.
Note: : Having multiple paths to a target can make access to that target more convenient.

Office Open XML imposes constraints on relationships, described in subsequent clauses of this part. Relationships in Office Open XML are either explicit or implicit.

For an explicit relationship, a resource is referenced from a source part’s XML using the @Id attribute of a <Relationship> tag.
example: : A document part can have a relationship to a hyperlink only if that hyperlink's <Relationship> element’s @Id attribute value is referenced explicitly by the document part’s XML.
Note: : Because this mechanism is used generically across multiple tag types, explicit relationships can be extracted from an Office Open XML document without prior knowledge of tag semantics.
. Certain relationships shall be explicit.. All other relationships are implicit
Note: : The syntax for specifying an implicit relationship varies among tag types.
. Relationships that are required or permitted, and restrictions on those relationships are described in §1015 of this Part.
example:

The Main Document part’s relationship file contains the following:

<Relationships …>
  <Relationship Id="rId5" Type="…/footnotes"
    Target="footnotes.xml"/>
  <Relationship Id="rId7" Type="…/hyperlink"
    Target="http://www.ecma-international.org/" TargetMode="External"/>
</Relationships>

All footnotes for a WordprocessingML document are contained in the same Footnotes part. Let’s look at how the Main Document refers to the footnote. At the point at which the footnote reference is inserted, the following XML is present:

<w:r>
	  <w:footnoteReference w:id="2"/>
</w:r>

The w:id=“2” refers to the footnote with id=2 in the Footnotes part, the relevant piece of which is:

<w:footnote w:id="2">
  …
  Ecma is an international standards development organization (SDO). 
  …
</w:footnote>

In the case of the hyperlink, the main document part makes an explicit reference to this relationship when it refers to the hyperlink, by using the following:

<w:hyperlink r:id="rId7" w:history="1"></w:hyperlink>

The important distinction here is that there is no explicit reference to a relationship ID designating the Footnotes part. The reference to the footnote with id=2 is “understood” to be in the Footnotes part that must always exist if there are any footnotes in the document. ]

example:

The dots correspond to attributes of relevant elements. Where one attribute refers to a piece in another part, this is indicated by arrows. Solid arrows indicate that the value of the source directly corresponds to the value at the target (for instance, @id=rId4 in the source part corresponds to @id=rId4 in the relationship item).

Dotted arrows indicate that the value of the source only implicit corresponds to the value of the target (for instance, "footnoteReference" in the source indicates the type "footnotes" in the relationship item).

The main difference between the two types of relationship is that for implicit relationships, the id of the reference refers to an element with the same id in the target part, whereas for explicit relationships, the id refers to a relationship with the same id in the relationship item.

Both relationship types use the target URI of the relationship in the relationship item to locate the target.

For explicit relationships, the id in the source XML links to a relationship item with a direct explicit reference to the target. For implicit relationships, the relationship item is implied by the containing tag (e.g., footnote) and the id in the source XML is used to locate the correct element within the implied target.

example:

example: