Show All

# GetContextNodes Method

Returns a reference to an XMLNodes collection that is populated with XML Document Object Model (DOM) nodes based on the current context. It consists of the sequence of XML DOM nodes that are mapped from the view, corresponding to the current XSL Transformation (XSLT) node, starting at the current selection and walking up through the view ancestors to the `BODY` tag.

expression.GetContextNodes([ByVal varNode As Variant], [ByVal varViewContext As Variant]) As XMLNodes

expression Required. An expression that returns a reference to the View object.

varNode Optional Variant. An XML DOM node.

varViewContext Optional Variant. The ID of the control that is used for the context.

returns A reference to the XMLNodes collection.

## Security Level

2: Can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

## Remarks

If no parameters are used, the context nodes are based on the current selection. If parameters are used, then the context nodes returned are those that would be returned based on the selection that would be obtained from calling the SelectNodes method of the View object.

## Example

In the following partial example from the Structural Editing developer sample form, the GetContextNodes method of the View object is used to return a collection of XML DOM nodes based on the current context. Then the code loops through the collection of XML DOM nodes looking for a particular node. When it is found, the code calls the custom ApplyDiscountToItem function to update the data that the node contains.

    objContextNodes = XDocument.View.GetContextNodes();

    // Scan the list of context nodes for an item node and if one is found
    // apply the discount to it.
    for (var i = 0; i < objContextNodes.Count; i++)
    {
       if (objContextNodes.item(i).nodeName == "item")
       {
          ApplyDiscountToItem(objContextNodes.item(i), intPercentage);
          blnAppliedDiscount = true;
          break;
       }
    }

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp