OpenDocument vs Microsoft OpenXML - Part II

For a high-level overview see part I of this article.

See also Microsoft and Open Standards - Can Other Vendors Implement Microsoft's Office Open XML?, published 15 August 2007 by Matthew Cruickshank, Chris Daish and Conal Tuohy, for another analysis and a list of other references.

Notation

ODF: OpenDocument Format (.odt)
OXML: Microsoft Office Open XML (.docx)

Introduction

This article is a technical comparison between ODF and OXML. We try to show you how the design of these formats affect interoperability. After all, interoperability is the purpose of open standards.

OpenDocument benefits from 5 years of development involving a broad range of experts in a standards body. It was written with the explicit purpose of being interoperable across different platforms. In contrast, OXML has not gone through a peer-review process, and was written with only one product in mind. This difference shows in the design of the formats.

What you should already know

We've tried to write this article for a general audience. But the ideal reader should be familiar with HTML.

As you read this article, think of the following:

  • Which format is more understandable?
    The easier a format is to learn, the easier it is to support. The programmers who create the tools you use will be able to create them more efficiently and reliably with the more understandable format.
     
  • Which format reuses existing standards?
    Reusing existing standards allows the programmer to reuse her existing skills and her existing tools. Also, existing standards are well tested and mature. We know that they work.

The basics

OXML and OpenDocument are both ZIP archives containing several files and directories. You can download a sample file of each from the website of Microsoft's Brian Jones.

The .odt file is OpenDocument translated from the .doc file; the .docx is OXML. Download both and unzip them.

Mixed content model

OpenDocument uses a mixed content model and OXML does not. But what is mixed content?

In non-mixed content, an element contains either other elements or text as its immediate children, but not both. A mixed content document allows text and elements to be freely mixed. As an example:

Non-mixed content Mixed content
<document>
 <name>Joe</name>
 <age>45</age>
 <address>
  <city>Pekin</city>
  <state>IL</state>
 </address>
</document>
<document>
 <para>Lets welcome <name>Joe</name> 
 to our team.</para>

 <para>He is <age>45</age> years old 
 and lives in <city>Pekin</city>,
 <state>Illinois</state>.</para>
</document>

Non-mixed documents usually represent structured data; mixed documents are usually used to represent narrative.

OXML uses the non-mixed model to represent narrative (word processing). This sort of mismatch leads to markup like this:

<w:p>
  <w:r>
    <w:t>This is a </w:t>
  </w:r>
  <w:r>
    <w:rPr>
      <w:b />
    </w:rPr>
    <w:t>very basic</w:t>
  </w:r>
  <w:r>
    <w:t> document </w:t>
  </w:r>
  <w:r>
    <w:rPr>
      <w:i />
    </w:rPr>
    <w:t>with some</w:t>
  </w:r>
  <w:r>
    <w:t> formatting, and a </w:t>
  </w:r>
  <w:hyperlink w:rel="rId4" w:history="1">
    <w:r>
      <w:rPr>
        <w:rStyle w:val="Hyperlink" />
      </w:rPr>
      <w:t>hyperlink</w:t>
    </w:r>
  </w:hyperlink>
</w:p>

The equivalent in OpenDocument would look like this:

<text:p text:style-name="Standard">
 This is a 
 <text:span text:style-name="T1">very basic</text:span>
 document
 <text:span text:style-name="T2">with some</text:span>
 formatting, and a
 <text:a xlink:href="http://example.com">hyperlink</text:a>
</text:p>

XHTML is also a mixed-content format:

<p>
  This is a <i>very basic</i> document
  <b>with some</b> formatting, and a 
  <a href="http://example.com">hyperlink</a>
</p>

Now, ask yourself:

  • Would you rather transform OXML to XHTML or transform ODF to XHTML?
  • If you already know XHTML, which format allows you to reuse your skills more?

Formatting

The different choice of model has an effect in how the format handles formatting. The mixed-content model makes more sense, and is closer to what a developer will be familiar to:

OXML

<w:r>
  <w:rPr>
    <w:b />
  </w:rPr>
  <w:t>this is bold</w:t>
</w:r>

OpenDocument

<text:span text:style-name="Strong_20_Emphasis">
    this is bold
</text:span>

In HTML you write <b>this is bold</b> or
<span class="mystyle">this is bold</span>

In DocBook you write <emphasis role="strong">this is bold</emphasis>

If you are a developer, used to existing technologies, which format allows you to reuse your current skills most?

Separation of content and presentation

Let's go back to the above code sample

OpenDocument

<text:span text:style-name="Strong_20_Emphasis">
    this is bold
</text:span>

Here, "Strong_20_Emphasis" refers to a style located elsewhere in the document. In this case, the style looks like this:

<style:style style:name="Strong_20_Emphasis"
 style:display-name="Strong Emphasis" style:family="text">
   <style:text-properties fo:font-weight="bold" />
</style:style>

OpenDocument always uses styles for formatting. Suppose you have a document with many related terms, and you decide that instead of bold you want a different font type. You just edit the style definition.

Now take another look at OXML:

<w:r>
  <w:rPr>
    <w:b />
  </w:rPr>
  <w:t>this is bold</w:t>
</w:r>

That <w:b /> means "bold". The formatting is embedded into the tag itself. If you have a document with many related terms and decide that you don't want the bold anymore, you have to find each term and change the tag.

To be fair, OXML does make an attempt to separate content and presentation. Both formats give you some separation, and neither format gives you perfect separation. But OpenDocument goes much further in that direction.

Separation into files

Along similar lines, OXML and OpenDocument both separate the document into several XML files (which are then zipped together). However, they go about it in different ways. For example:

OXML

<w:hyperlink w:rel="rId1" w:history="1">
  <w:r>
    <w:t>This is a hyperlink</w:t>
  </w:r>
</w:hyperlink>

Notice that we don't actually know where this hyperlink is pointing with the OXML file - we have to look that up in a completely separate file.

OpenDocument

<text:a xlink:href="http://example.com">
    This is a hyperlink
</text:a>

Here we immediately know where the link is pointing. This example takes us to our next point...

Reuse of standards

OpenDocument reuses existing standards whenever possible. It uses SVG for drawings, MathML for equations, etc. This makes the format much more transparent to someone familiar with XML technologies. It also allows you to reuse existing tools that understand these standards. In contrast, Microsoft has decided to reinvent the wheel at every turn.

Look back at the example hyperlink above; you'll see the attiribute prefixed with xlink. What is XLink?

XLink

XLink is the XML Linking Language. It is an industry standard for references. Rather than reinventing the wheel, OpenDocument simply uses the existing mechanism.

XLink is used in many ways in OpenDocument - for example, embedding images. OXML and OpenDocument both reference an image file within the ZIP archive. But compare:

OXML

<w:pict>
  <v:imagedata w:rel="rId1" o:title="My Image"/>
</w:pict<

OpenDocument

<draw:frame>
  <draw:image xlink:href="Pictures/000000001.jpg"
              xlink:type="simple" xlink:show="embed"
              xlink:actuate="onLoad"/>
</draw:frame>

OpenDocument lets a developer reuse her existing knowledge of XML technologies. And her XLink-aware tools will work with OpenDocument.

Metadata

Once again, where OpenDocument relies on a published standard, OXML re-invents the wheel. OpenDocument uses the Dublin Core metadata standard. Any DC-aware application can add/view/update the metadata without having to understand OpenDocument.

OXML

<Title>My document</Title>
<Creator>Joe User</Creator>
<DateCreated>2005-11-24T01:26:30</DateCreated>

OpenDocument

<dc:title>My document</dc:title>
<dc:creator>Joe User</dc:creator>
<dc:date>2005-11-24T01:26:30</dc:date>

In this case the OXML markup is very similar. But since it's not quite the same, a standard tool that knows Dublin Core will not automatically understand Microsoft's format (XML is case sensitive). You still need a new tool.

References