9.2 Relationships in Office Open XML

9.2 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. end note]

Office Open XML imposes constraints on relationships, described in subsequent clauses of this Part of ISO/IEC 29500. 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. end example] [Note: Because this mechanism is used generically across multiple XML elements, explicit relationships can be extracted from an Office Open XML document without prior knowledge of tag semantics. end note]. Certain

relationships shall be explicit. All other relationships are implicit. [Note: The syntax for specifying an implicit relationship varies based on the content model of the XML element which is the source of the relationship. end note]. Relationships that are required or permitted, and restrictions on those relationships are described in 10–15 of this Part of ISO/IEC 29500.

[Example: Consider a WordprocessingML document that contains the following footnote sentence fragment, “… 1 produced by Ecma (http://www.ecma-international.org/).”, which contains a footnote and a hyperlink to a web site. The relationship from a source to a footnote is implicit while that to a hyperlink is explicit.

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. end example]

[Example: The following figure shows how the source, relationship item, and the target relate to each other for implicit and explicit relationships, respectively. The target does not have to be a file, however.

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 relationship 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 maps directly to the id of 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.

image

end example]

[Example: The following figure shows

image

end example]

the

[Example: The following figure shows

implicit relationship for the

an explicit relationship.

footnote example

described earlier.

image

end example]

Last updated on