Udostępnij za pośrednictwem


XMLNode control

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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 to document-level projects for Word. For more information, see Features available by Office 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 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.

Bind 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

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

Events

The following events are available for the XMLNode control:

Compare 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:

<Customer>
    <Company>
        <CompanyName>
        <CompanyRegion>

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