none
Apparent duplicate ID in <Relationship> Office Open XML elements RRS feed

  • Question

  • Hi there,

    I'm looking to evaluate the target of a hyperlink field from the Office Open XML in order to work out how many spaces in the corresponding Word.Range are filled with non-text content (i.e. the HYPERLINK field).  It turns out the <hyperlink/> element is handled relationally, i.e. there is a separate <Relationship/> element with an Id attribute linking it to the hyperlink and a Target attribute containing the hyperlink target.

    So I looked for this in the front of the Word document and found this:

    <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512">
    <pkg:xmlData>
    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml" /> 
    </Relationships>
    </pkg:xmlData>
    </pkg:part>
    <pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="256">
    <pkg:xmlData>
    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" Target="webSettings.xml" /> 
    <Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml" /> 
    <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml" /> 
    <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml" /> 
    <Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml" /> 
    <Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://www.google.co.uk/" TargetMode="External" /> 
    <Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://www.google.co.uk/" TargetMode="External" /> 
    </Relationships>
    </pkg:xmlData>
    </pkg:part>
    
    

    What bothers me slightly is that rId1 appears twice: there is no unique rId1 target.  I'm actually after rId4 and rId5 so this doesn't currently concern me directly, but I don't want to store two key/value pairs in my program with the same key (which is one option) and I don't want to choose to pick up relationships from one of the package elements arbitrarily, only to find later that my arbitrary choice was wrong, or conditional on factors I don't understand, or something.

    Can someone explain the namespaces to me, or show me an article that explains them?  I would like to be certain that I've picked the right set of <Relationship/> elements.  I've tried to find information in the ECMA-376/4 document but unfortunately I don't know exactly where to look (and there are 5220 pages to choose from).

    Thanks!

    Sunday, December 19, 2010 6:35 PM

Answers

  • Section 9.3.1 ("Relationships Part") of the ISO standard for Open Packages states:
     

    Each set of relationships sharing a common source is represented by XML stored in a Relationships part.

     
    ... and section 9.3.2 ("Relationship Markup") says:
     

    The package implementer shall require that every Relationship element has an Id attribute, the value of which is unique within the Relationships part, ...

     
    In your case, the 'common source' is the document.xml part, specified by:
     
    <pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contentType ...
     
    and the Relationships within that, wherein "rId1" is unique. IDs in other Relationships, in other Parts, have no relationship (excuse the pun) to the ones you want to look at.
     

    Enjoy,
    Tony
    www.WordArticles.com
    • Marked as answer by andrewwyld Tuesday, December 21, 2010 3:12 PM
    Monday, December 20, 2010 7:38 AM

All replies

  • Section 9.3.1 ("Relationships Part") of the ISO standard for Open Packages states:
     

    Each set of relationships sharing a common source is represented by XML stored in a Relationships part.

     
    ... and section 9.3.2 ("Relationship Markup") says:
     

    The package implementer shall require that every Relationship element has an Id attribute, the value of which is unique within the Relationships part, ...

     
    In your case, the 'common source' is the document.xml part, specified by:
     
    <pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contentType ...
     
    and the Relationships within that, wherein "rId1" is unique. IDs in other Relationships, in other Parts, have no relationship (excuse the pun) to the ones you want to look at.
     

    Enjoy,
    Tony
    www.WordArticles.com
    • Marked as answer by andrewwyld Tuesday, December 21, 2010 3:12 PM
    Monday, December 20, 2010 7:38 AM
  • Thank you—I thought it must be something like that but I wanted to check that the relationship table name was static and I could rely on finding it.  Cheers!
    Tuesday, December 21, 2010 5:39 PM
  • I know Tony's post has given you the info. you need, but FWIW I ever managed to find a schema for the FlatOPC Namespace (i.e. the one whose Namespace URI is

    http://schemas.microsoft.com/office/2006/xmlPackage

    I always assumed that it was because "OPC" is a "Convention", not a "Standard", and that only the .zip-based implementation of the convention have ended up in the ECMA/ISO standards. 

    However, since FlatOPC is actually quite widely used, it would be handy to have a proper schema!


    Peter Jamieson
    Thursday, December 23, 2010 9:37 AM