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 a VSTO Add-in 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 VSTO Add-in projects for Excel, PowerPoint, and Word. For more information, see Features Available by Office Application and Project Type.
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:
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 VSTO 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 VSTO Add-in, you can create or modify custom XML parts in any document that is open in the application.
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.
XML Schemas and Data in Document-Level Customizations
How to: Add Custom XML Parts to Document-Level Customizations
How to: Add Custom XML Parts to Documents by Using VSTO Add-Ins
Walkthrough: Binding Content Controls to Custom XML Parts