XPS This is the second part of the Dissecting XPS series, last post generally described the XML Paper Specification. This post in the series will describe the XPS file format internals. This will give you an overview of how the XPS files are built from ground and up, instead of reading the XPS Specification which covers 453 pages.

The XPS file

The XPS file, with the .xps extension, is a ZIP file - called the physical Package, and consists of a number of XML and binary files - called Parts. There are also files describing how the files are organized and connected together - called Relationships

Payload

The parts and relationships is grouped into a Payload, according to the Open Packaging Convention[1], and an XPS document must contain at least one fixed payload, which represents a “static or fixed-layout representation of a paginated content” [2]. Each fixed payload starts with a FixedDocumentSequence, which describes the sequence of fixed documents.

FixedDocumentSequence

The FixedDocumentSequence contains references to to the fixed documents in the XPS document. Each XPS Document must contains a specific relationship which identifies the FixedDocumentSequence that is the root of the document, called the XPS Document StartPart, so consumers of the document can find the first document sequence.

The start part relationships is stored in a .rels file in the /_rels folder and contains a reference to the the part containing the FixedDocumentSequence.

The code below shows the start part relationship file, and line 5 shows the relationship to the fixed document sequence.

.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, “Courier New”, courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; overflow-x:visible;border:0px} .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

   1:  <>xml version="1.0" encoding="UTF-8" standalone="yes"?>
   2:  Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
   3:  Relationship Id="rId3"          Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"          Target="docProps/core.xml"/>
   4:  Relationship Id="rId2"          Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"          Target="docProps/thumbnail.jpeg"/>
   5:  Relationship Id="rId1"          Type="http://schemas.microsoft.com/xps/2005/06/fixedrepresentation"          Target="FixedDocSeq.fdseq"/>
   6:  Relationships>

The Type attribute on line 5 has the value of http://schemas.microsoft.com/xps/2005/06/fixedrepresentation, which indicates that this is the StartPart [2: Table I-6]. Note that all targets have a paths that are relative to the parent of the _rels folder.

In the example above (taken from the XPS Specification) there are also two other relationships; line 3 tells us where to find the properties for the XPS document and line 4 shows the reference to the thumbnail image of the document, in this case a JPEG file. I will get back to these Parts later in the series.

This is the content of the FixedDocSeq.fdseq file, referenced above on line 5, in this case the XPS document has two fixed documents.

   1:  FixedDocumentSequence xmlns="http://schemas.microsoft.com/xps/2005/06"> 
   2:     DocumentReference Source="Documents/1/FixedDocument.fdoc" /> 
   3:     DocumentReference Source="Documents/2/FixedDocument.fdoc" /> 
   4:  FixedDocumentSequence> 

Line 2 and 3 contains document references to the fixed documents, their location is specified using the Source attribute and is relative to the file.

This image shows how the different parts and relationships are located in the ZIP compressed XPS document.

Brief overview of an XPS Document

The start part is found in the /_rels/.rels file, and then the document sequence can be found and then the fixed documents which contains the contents. The relationships file also points out where the thumbnail and document properties are stored.

There are also an important file called [Content_Types].xml containing the content types for the different files, located in the root. This file is specified in the Open Packaging Convention standard[2].

   1:  <>xml version="1.0" encoding="UTF-8" standalone="yes"?>
   2:  Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
   3:    Default Extension="rels"              ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
   4:    Default Extension="fdseq"              ContentType="application/vnd.ms-package.xps-fixeddocumentsequence+xml"/>
   5:    Default Extension="fpage"              ContentType="application/vnd.ms-package.xps-fixedpage+xml"/>
   6:    Default Extension="jpg"              ContentType="image/jpeg"/>
   7:    Default Extension="fdoc"              ContentType="application/vnd.ms-package.xps-fixeddocument+xml"/>
   8:  Types>

If you rename the XPS document to .ZIP you can easily look into the structure of the XPS file and find the parts and relationships.

The image above shows the root of an XPS document.

The FixedDocument Part

The FixedDocument Part is the root for all pages in the document (a set of fixed pages) and we will look into this Part and others in the next part of this Dissecting XPS series.

Further reading and references

[1] Open Packaging Convention[2] XPS Specification[3] Dissecting XPS, part 1 - The basics