OpenXML Share Point 2010

As described at the beginning of this chapter, OpenXML is an XML-based file format that’s supported by applications in the Microsoft Office 2007 suite and later. Although an in-depth discussion on all aspects of OpenXML is beyond the scope of this chapter, we’ll take a look at a few of the key objects and work through an example showing how the technology can be used when building SharePoint applications.

NOTEAlthough OpenXML files are XML-based and can therefore be created and modified by using the various XML manipulation classes that are present in the .NET Framework, Microsoft provides an OpenXML SDK to make it easier to deal with the complex document structure in managed code.

Getting Started with OpenXML
OpenXML documents are in fact ZIP files. Each ZIP archive contains a collection of XML files and other elements. Relationships exist among the different XML files stored within the archive, and these relationships are defined in XML format in files with a .rels file extension.

TIPTo see how an OpenXML archive is structured, try renaming a .docx file to .zip and then open it with Windows Explorer. Many of the files in the archive serve a particular function. For example, the fontTable .xml file contains details of the fonts that are in use within a document. Word documents store an XML file named document.xml; if you examine this file, you’ll see most of the user-generated content.

Dealing with each of the individual files and maintaining references between them by using standard XML processing components such as XmlDocument and XPathNavigator is certainly possible. However, it should be apparent from looking at the number of files involved that such an approach is no trivial undertaking. With that in mind, we’ll continue our discussion with a focus on the object model provided by the OpenXML SDK. Within the OpenXML object model, a document is represented by a class derived from the OpenXmlPackage class. A document is actually a ZIP archive containing many files, and each of these files is defined as an object derived from OpenXmlPart. For example, the main document element in a Word file can be referenced by examining the Main Document Part property of a Word Processing Document object. Word Processing Document inherits from OpenXmlPackage and MainDocumentPart inherits from OpenXmlPart. Each OpenXmlPart is made up of one or more OpenXml Element objects, which in turn can contain OpenXml Attribute objects. Naturally, these are abstract objects and specific implementations will often be used when processing a document. For example, when adding a Caption to a WordProcessingDocument object, an instance of the WordProcessing.Caption class will be used.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Share Point 2010 Topics