theThought's thoughts

Kevin A Gray - Creative Strategy Guy

Three Critical Parts to an OpenXML package

So the first thing to learn is the basic, underlying structure to an openXML document whether it is for Word, Excel or Powerpoint.  Each document is a compressed collection of XML documents wrapped into a single file.  Each of these XML documents is called a “part” while the wrapper is called a package.

When a new package is created it must consist of three core elements:

·         A MainPart – this is the main document being created

·         A CollectionTypes Part – this describes the types of parts that are included in the document (Word, Excel, Powerpoint, image, video etc)

·         A relationships part – this defines the relationships between each part

A package must contain all three, if it does not then it is not considered a valid package, it is effectively just a WinZip file with a funny extension.

The easiest way to see this is to perform the following steps:

1.       Open Word 2007 (or later)

2.       Enter a single line of text

3.       Save the document as a DOCx file

4.       Close the document

5.       Open Winzip

6.       Select Open Archive from the File menu

7.       Point to the DOCx file

8.       Click OK

The following figure shows what the zip file should look like.

Fig_1

As can be seen from this image there are three files in the package.  The first is the relationships file (.rels) this sits is a sub-folder off the root of the document.  The second is the content types document and the last is the main part of the document that contains the content of this document.  Each of them is a well formed XML document.

In version 1.0 of the openXML SDK each of these parts would have to be created manually then placed together into a single compressed file.  In version 2.0 of the openXML SDK there are methods that allow the rapid creation of these three documents by simply creating the main part document.

Filed under  //   ContentTypes   DOCx   Excel   MainPart   OpenXML   OpenXML SDK 2.0   Package   PowerPoint   Relationships   SPSS   WinZip   Word 2007