Screen-Cast: Using the Markup Compatibility / Extensibility Feature of the Open XML SDK

Open XML is designed in such a way that as Office suites evolve, they can implement new features.  However, older versions of the Office suite will not be able to process new markup, so to handle this situation, the Open XML standard defines some elements that enable a newer Office suite to write both old markup and new markup.  Then, an older version of a word processor can read and process the old markup, and the document will render in the best way possible in that version.  This means that there will be two versions of the markup in the document – the old and the new.  Consider a WordprocessingML document that contains a text box:

<w:p>
  <w:r>
    <w:rPr>
      <w:noProof/>
    </w:rPr>
    <mc:AlternateContent>
      <mc:Choice Requires="wps">
        <w:drawing>
          <wp:anchor distT="45720"
                      distB="45720"
                      distL="114300"
                      distR="114300"
                      simplePos="0"
                      relativeHeight="251659264"
                      behindDoc="0"
                      locked="0"
                      layoutInCell="1"
                      allowOverlap="1">
            <wp:simplePos x="0"
                          y="0"/>
            <wp:positionH relativeFrom="column">
              <wp:align>center</wp:align>
            </wp:positionH>
            <wp:positionV relativeFrom="paragraph">
              <wp:posOffset>182880</wp:posOffset>
            </wp:positionV>
            <wp:extent cx="2360930"
                        cy="1404620"/>
            <wp:effectExtent l="0"
                              t="0"
                              r="22860"
                              b="11430"/>
            <wp:wrapSquare wrapText="bothSides"/>
            <wp:docPr id="1"
                      name="Text Box 2"/>
            <wp:cNvGraphicFramePr>
              <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
            </wp:cNvGraphicFramePr>
            <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
              <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                <wps:wsp>
                  <wps:cNvSpPr txBox="1">
                    <a:spLocks noChangeArrowheads="1"/>
                  </wps:cNvSpPr>
                  <wps:spPr bwMode="auto">
                    <a:xfrm>
                      <a:off x="0"
                              y="0"/>
                      <a:ext cx="2360930"
                              cy="1404620"/>
                    </a:xfrm>
                    <a:prstGeom prst="rect">
                      <a:avLst/>
                    </a:prstGeom>
                    <a:solidFill>
                      <a:srgbClr val="FFFFFF"/>
                    </a:solidFill>
                    <a:ln w="9525">
                      <a:solidFill>
                        <a:srgbClr val="000000"/>
                      </a:solidFill>
                      <a:miter lim="800000"/>
                      <a:headEnd/>
                      <a:tailEnd/>
                    </a:ln>
                  </wps:spPr>
                  <wps:txbx>
                    <w:txbxContent>
                      <w:p>
                        <w:r>
                          <w:t>Here is a text box.</w:t>
                        </w:r>
                      </w:p>
                    </w:txbxContent>
                  </wps:txbx>
                  <wps:bodyPr rot="0"
                              vert="horz"
                              wrap="square"
                              lIns="91440"
                              tIns="45720"
                              rIns="91440"
                              bIns="45720"
                              anchor="t"
                              anchorCtr="0">
                    <a:spAutoFit/>
                  </wps:bodyPr>
                </wps:wsp>
              </a:graphicData>
            </a:graphic>
            <wp14:sizeRelH relativeFrom="margin">
              <wp14:pctWidth>40000</wp14:pctWidth>
            </wp14:sizeRelH>
            <wp14:sizeRelV relativeFrom="margin">
              <wp14:pctHeight>20000</wp14:pctHeight>
            </wp14:sizeRelV>
          </wp:anchor>
        </w:drawing>
      </mc:Choice>
      <mc:Fallback>
        <w:pict>
          <v:shapetype id="_x0000_t202"
                        coordsize="21600,21600"
                        o:spt="202"
                        path="m,l,21600r21600,l21600,xe">
            <v:stroke joinstyle="miter"/>
            <v:path gradientshapeok="t"
                    o:connecttype="rect"/>
          </v:shapetype>
          <v:shape id="Text Box 2"
                    o:spid="_x0000_s1026"
                    type="#_x0000_t202"
                    style="position:absolute;margin-left:0;margin-top:14.4pt;width:185.9pt;height:110.6pt;z-index:251659264;visibility:visible;
mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:3.6pt;mso-wrap-distance-
right:9pt;mso-wrap-distance-bottom:3.6pt;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:absolute;
mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top"> <v:textbox style="mso-fit-shape-to-text:t"> <w:txbxContent> <w:p> <w:r> <w:t>Here is a text box.</w:t> </w:r> </w:p> </w:txbxContent> </v:textbox> <w10:wrap type="square"/> </v:shape> </w:pict> </mc:Fallback> </mc:AlternateContent> </w:r> </w:p>

You can see the mc:AlternateContent element, which contains two child elements, ms:Choice and mc:Fallback.  The mc:Choice element contains the modern, strict markup that is written using DrawingML.  The mc:FallBack element contains the old, transitional (deprecated) markup that is written in VML.

Depending on your particular scenario, you may want to produce a document that can be read by Office 2007, or you may not be concerned about 2007 and want to produce a document that can be read by Office 2010 or later.  The Markup Compatibility / Extensibility feature of the SDK enables easier processing of such markup.  The following screen-cast explains how to use the MCE feature of the SDK, and demonstrates a small program that makes use of it.