XMLNode Control

Important   The information set out in this topic regarding Microsoft Word is presented exclusively for the benefit and use of individuals and organizations who are located outside the United States and its territories or who are using, or developing programs that run on, Microsoft Word products that were licensed by Microsoft before January 2010, when Microsoft removed an implementation of particular functionality related to custom XML from Microsoft Word. This information regarding Microsoft Word may not be read or used by individuals or organizations in the United States or its territories who are using, or developing programs that run on, Microsoft Word products that were licensed by Microsoft after January 10, 2010; those products will not behave the same as products licensed before that date or purchased and licensed for use outside the United States.

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

Microsoft Office version

  • Word 2007

  • Word 2003

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

The XMLNode control is a mapped XML node object that exposes events and can be bound to data. The XMLNode control is created only when a non-repeating schema element is mapped onto a Microsoft Office Word document. After Visual Studio Tools for Office creates the XML node, you can program against it directly without having to traverse the Word object model.

The XMLNode control can be deleted only by removing the element mapping in Word.

Binding Data to the Control

An XMLNode control supports simple data binding. The XML node should be bound to a data source by using the DataBindings property. If the data in the bound dataset is updated, the XMLNode control reflects the changes.


Formatting that can be applied to a XMLNode object can be applied to a Microsoft.Office.Tools.Word.XMLNode control. This includes fonts, underline styles, and character styles.


The following events are available for the XMLNode control:

Comparing Events

You can capture an event when the user moves his or her cursor inside the context of a particular XMLNode control. For example, you might have an XMLNode control named Customer that has a child XMLNode control named Company, and Company has two child XMLNode controls named CompanyName and CompanyRegion as follows:


If you want to show a control on the actions pane whenever the cursor is moved into the Company node, it should not matter whether the cursor is placed in CompanyName or CompanyRegion because they are both within the context of Company. In this case, you can write your code in the ContextEnter event of Company.

In most cases, when the cursor enters an XMLNode control, both the Select and ContextEnter events are raised. The following table shows the differences between these events.

Select Event

ContextEnter Event

Occurs when the cursor is placed inside an XMLNode.

Occurs when the cursor is placed inside an XMLNode or one of its descendent nodes, from an area outside of the context of the node. In other words, it is raised only when the context changes.

For example, when you move the cursor from outside of Customer into CompanyName, the ContextEnter event for Customer, Company, and CompanyName is raised. If you then move the cursor from CompanyName to CompanyRegion, only the ContextEnter event for CompanyRegion is raised because you are still within the context of both Company and Customer.

The same differences exist between the ContextLeave event and Deselect event.

See Also


How to: Add XMLNode Controls to Word Documents

How to: Map Schemas to Word Documents Inside Visual Studio

Walkthrough: Changing the Actions Pane According to User Context


Host Items and Host Controls Overview

XMLNodes Control

Programmatic Limitations of Host Items and Host Controls

Other Resources

Word Host Controls

Excel Host Controls