Dela via


Custom XML Parts Overview

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2007

  • PowerPoint 2007

  • Word 2007

For more information, see Features Available by Application and Project Type.

You can embed XML data in documents for some applications in the 2007 Microsoft Office system. 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 Tools for Office. You do not need to start the Microsoft Office application to create and modify custom XML parts.

Note

Visual Studio Tools for Office 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 Data Model in Document-Level Customizations.

Understanding Custom XML Parts

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

Excel 2007, Word 2007, and PowerPoint 2007 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.

Creating and Modifying Custom XML Parts

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.

Modifying XML Parts While the Office Application Is Running

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 Tools for Office, add a new Microsoft.Office.Core.CustomXMLPart to the Microsoft.Office.Core.CustomXMLParts collection in the document. These classes are provided by the primary interop assemblies for the 2007 Microsoft Office system. For more information, see the following topics:

Modifying XML Parts Without Starting the Office 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, there are two options:

Binding Custom XML Parts to Word Content Controls

You can bind content controls in a Word 2007 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.

See Also

Tasks

How to: Add Custom XML Parts to Document-Level Customizations

How to: Add Custom XML Parts to Documents by Using Application-Level Add-Ins

How to: Add Custom XML Parts to Documents Without Starting Microsoft Office

Walkthrough: Binding Content Controls to Custom XML Parts

Concepts

XML Schemas and Data (Visual Studio Tools for Office)

Content Controls

Change History

Date

History

Reason

August 2008

Added information about the Open XML Format SDK.

Information enhancement.