Export (0) Print
Expand All

Custom XML Parts Overview

You can embed XML data in documents for some Microsoft Office applications. When you embed XML data in a document, the data is named a custom XML part.

You can create and modify custom XML parts in a document by using an application-level or document-level solution in Visual Studio. You do not need to start the Microsoft Office application to create and modify custom XML parts.

Applies to: The information in this topic applies to document-level projects and application-level projects for the following applications: Excel 2010; PowerPoint 2010; Word 2010. For more information, see Features Available by Office Application and Project Type.

Note Note

Visual Studio also enables you to cache data objects in document-level customizations. This feature is different from custom XML parts, although there are some similarities. For more information, see Cached Data in Document-Level Customizations.

Custom XML parts were introduced in the 2007 Microsoft Office system, along with the Open XML Formats. These formats include new XML-based file formats for Excel, PowerPoint, and Word (such as .xlsx, .pptx, and .docx). Documents in these formats consist of XML files (also named XML parts) that are organized in folders in a ZIP archive. Most of the XML parts are built-in parts that help to define the structure and the state of the document. However, documents can also contain custom XML parts, which you can use to store arbitrary XML data in the documents.

The XML file formats enable applications to work with documents in ways that are not possible with the older binary file formats (such as .xls, .ppt, and .doc). Any application that can read ZIP archives can examine and modify the contents of the documents, even if Microsoft Office is not installed.

For more information about the structure of Open XML and custom XML parts, see the following articles:

Note Note

Excel, Word, and PowerPoint also enable you to use custom XML parts in documents that are saved in the binary file formats. However, if a document is saved in a binary format, you cannot add or modify custom XML parts without starting the Microsoft Office application.

You can create or modify custom XML parts when the document is open in the Office application, or when the document is closed—even if Microsoft Office is not installed.

You can work with custom XML parts by using a document-level customization or an application-level add-in. If you are using a document-level customization, you will typically work with custom XML parts that are in the customized document. If you are using an application-level add-in, you can create or modify custom XML parts in any document that is open in the application.

To create a custom XML part by using Visual Studio, add a new CustomXMLPart to the CustomXMLParts collection in the document. For more information, see the following topics:

You can add or modify a custom XML part without starting Excel, PowerPoint, or Word. This is useful if you want to work with XML data in a document on a computer that does not have Microsoft Office applications installed, such as a server.

To add a custom XML part without starting Microsoft Office, use classes in the Open XML SDK. These classes are designed to provide access to Open XML content that is specific to Office documents. For example, to add a custom XML part to an Excel workbook, you use the AddNewPart<T> method of a WorkbookPart object. For more information, see Open XML SDK 2.0.

You can bind content controls in a Word solution to elements in a custom XML part. When a content control is bound to a custom XML part, the data in the custom XML part is displayed in the user interface (UI) of the content control. If a user edits text in the control, the corresponding XML element is automatically updated. Similarly, if element values in the custom XML parts are changed, the content controls that are bound to the XML elements display the new data. For more information, see Content Controls.

Show:
© 2014 Microsoft