wordpress hit counter
Relative External References - Open Packaging Convention - Formats - OpenXML Developer

Relative External References

Formats

Discussions about working with different Open XML Formats

Relative External References

  • rated by 0 users
  • This post has 6 Replies |
  • 1 Follower
  • Although my experiences are with a Word Document, I presume this all holds for other apps as well.

    I created a blank document. I put the document and an image into a folder. I then edited the document to link to the image, and saved it. The relevant xml - in document.xml.rels - is:

    Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="file:///C:\Users\Tony\Desktop\Test\image1.jpeg" TargetMode="External" /

    (apologies for the format - I can't work out how to post xml)

    Elsewhere in the document xml, the image is referenced using the Id ("rId4"). This is all fine, and it works, and it makes sense, and it is as per the package standard.

    Now, it is pretty useless to me having this hard coded absolute path in the file and I want to make it relative. According to the standard - ISO 29500-2 Open Packaging Conventions, Paragraph 9.3.2.2 Relationship Element, ...

    When [the TargetMode is] set to External, the Target attribute can be a relative reference or a URI. If the Target attribute is a relative reference, then that reference is interpreted relative to the location of
    the package.


    So all I have to do is change the URI to a relative reference (relative to the location of the package) and all should be well. I edit the xml to say:

    Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="image1.jpeg" TargetMode="External" /

    The image file is in the same folder as the package, so now Target is a relative reference to it. Simple!

    When I now try to open the document, Word tells me it is corrupt.

    Assuming I haven't made a complete dog's dinner of what I'm doing (certainly possible), the document is not corrupt, and it is simply the case that Word does not support every part of the packaging standard. As I read it, this is allowable, but documents are not 'corrupt' just because they use features of the standard that are not implemented in Word. Randomly supporting only certain aspects of the standard, and not saying which ones, makes what Word 2007 does no better than what earlier versions did using the old proprietary binary format (which was much easier to understand).

    Is there anything I can do?

  • Hi Tony!

    Unfortunately I must say that I think you have got something else wrong in your package.

    I have just done exactly what you described, that is created a Word document with an external image, and it works fine.

    I did hit a minor problem along the way though, but that was my own fault. I got the image in the wrong place. So make sure you actually have the image in the same folder as the docx and not in a parent folder which is what I happened to do...

    But as soon as I moved the image to the right location, it seemed to work nicely. I even tried a few different values for the Target property, such as "file://image1.jpeg" and "image1.jpeg", and they all seemed to work...

    Having the target pointing to the wrong place does however not cause Word to say it is corrupt. It only makes Word show an empty image.

    Are you sure you packaged the right thing? Cause what I happened to do was that I renamed the docx to zip and unpacked it. I then made my changes and re-zipped the folder with files and not the files inside the unzipped folder... Simple mistake to make I assume, but will definitely get Word telling you that the document is corrupt...

    Cheers!
  • great.
  • thanks for this information, i was looking for it.
    regards

    alex
  • If I have a Wordpress or other hosted blog, may I need to export my blog as an XML first? And is there any missing on this proc "<cp:coreProperties xmlns:cp=""http://schemas.openxmlformats.org/package/2006/metadata/core-properties""></cp:coreProperties>" ?
    Thank you.
  • @GarminForerunner,

    I'm not quite clear on your question. What is it that you are trying to do?

    -Eric
  • Returning here after a long absence, assured the site is off life support!

    intergen:

    This issue appears to have been fixed in Word 2010, which is excellent. Given the date of your reply, perhaps that is what you were using to test

    It was disappointing when I first asked the question that no help was forthcoming from any forum, and, indeed, I have still seen no suggestion that I was doing anything wrongly, or admission that there ever was a problem - such is life.

Page 1 of 1 (7 items)