Edit

Share via


View.GetContextNodes Method

Definition

Overloads

GetContextNodes(XPathNavigator)

Gets a reference to an XPathNodeIterator object for iterating over the returned XML nodes starting from the specified node.

GetContextNodes(XPathNavigator, String)

Gets a reference to an XPathNodeIterator for iterating over the returned XML nodes in the current selection within the control bound to the specified control.

GetContextNodes()

Gets a reference to an XPathNodeIterator for iterating over the returned XML nodes in the current selection.

GetContextNodes(XPathNavigator)

Gets a reference to an XPathNodeIterator object for iterating over the returned XML nodes starting from the specified node.

public:
 abstract System::Xml::XPath::XPathNodeIterator ^ GetContextNodes(System::Xml::XPath::XPathNavigator ^ xmlNode);
public abstract System.Xml.XPath.XPathNodeIterator GetContextNodes (System.Xml.XPath.XPathNavigator xmlNode);
abstract member GetContextNodes : System.Xml.XPath.XPathNavigator -> System.Xml.XPath.XPathNodeIterator
Public MustOverride Function GetContextNodes (xmlNode As XPathNavigator) As XPathNodeIterator

Parameters

xmlNode
XPathNavigator

An object that specifies an XML node.

Returns

An XPathNodeIterator that is populated with the nodes starting from the specified node.

Exceptions

The GetContextNodes method was called from an event handler for the Loading event.

The parameter passed to this method is a null reference (Nothing in Visual Basic).

The parameter passed to this method is not valid. For example, it is of the wrong type or format.

Examples

In the following example, the SelectNodes(XPathNavigator) method is used to select the nodes in the first row of a Repeating Table control bound to group2. The GetContextNodes method is then used to return a collection of context nodes based on the current selection and the specified node. Finally, the code then loops through the collection of context nodes and displays the name, inner XML, and value of each node.

// Create XPathNavigator and specify XPath for nodes.
XPathNavigator repeatingTableRow1 = 
   MainDataSource.CreateNavigator().SelectSingleNode(
   "/my:myFields/my:group1/my:group2[1]", NamespaceManager);

// Select nodes in specified XPathNavigator.
CurrentView.SelectNodes(repeatingTableRow1);

// Get context nodes in selection.
XPathNodeIterator contextNodes = 
   CurrentView.GetContextNodes(repeatingTableRow1);

// Loop through collection and display information.
foreach (XPathNavigator contextNode in contextNodes)
{
   MessageBox.Show(contextNode.Name);
   MessageBox.Show(contextNode.InnerXml);
   MessageBox.Show(contextNode.Value);
}
' Create XPathNavigator and specify XPath for nodes.
Dim repeatingTableRow1 As XPathNavigator  = _
   CreateNavigator().SelectSingleNode( _
   "/my:myFields/my:group1/my:group2[1]", NamespaceManager)

' Select nodes in specified XPathNavigator.
CurrentView.SelectNodes(repeatingTableRow1)

' Get context nodes in selection.
Dim contextNodes As XPathNodeIterator = _
   CurrentView.GetContextNodes(repeatingTableRow1)

' Loop through collection and display information.
Dim contextNode As XPathNavigator
For Each contextNode In contextNodes
   MessageBox.Show(contextNode.Name)
   MessageBox.Show(contextNode.InnerXml)
   MessageBox.Show(contextNode.Value)
Next

Remarks

The XML nodes returned by the GetContextNodes method consists of a sequence of nodes that are mapped from the view, corresponding to the current XSL Transformation (XSLT) node, starting at the specified node and walking up through the view ancestors to the BODY tag.

If specified nodes are bound to more than one control in the view, you must use the GetContextNodes(XPathNavigator, String) method instead which allows you to specify the ViewContext identifier of the control that is bound to the nodes you want to iterate over.

Note: The GetContextNodes method will not return nodes based on the current selection if used in the event handler for the Clicked event of a button in the view, because the focus is lost from the control that is intended to be in context. To avoid this behavior, use GetContextNodes from a custom task pane, menu, or toolbar.

This member 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.

This type or member can be accessed only from code running in forms opened in Microsoft InfoPath Filler.

Applies to

GetContextNodes(XPathNavigator, String)

Gets a reference to an XPathNodeIterator for iterating over the returned XML nodes in the current selection within the control bound to the specified control.

public:
 abstract System::Xml::XPath::XPathNodeIterator ^ GetContextNodes(System::Xml::XPath::XPathNavigator ^ xmlNode, System::String ^ controlId);
public abstract System.Xml.XPath.XPathNodeIterator GetContextNodes (System.Xml.XPath.XPathNavigator xmlNode, string controlId);
abstract member GetContextNodes : System.Xml.XPath.XPathNavigator * string -> System.Xml.XPath.XPathNodeIterator
Public MustOverride Function GetContextNodes (xmlNode As XPathNavigator, controlId As String) As XPathNodeIterator

Parameters

xmlNode
XPathNavigator

An object that specifies the node to get.

controlId
String

The ViewContext identifier of the control that contains the currently selected XML nodes to return.

Returns

An XPathNodeIterator that is populated with the nodes in the current selection.

Exceptions

The GetContextNodes method was called from an event handler for the Loading event.

The parameters passed to this method are a null reference (Nothing in Visual Basic).

The parameters passed to this method are not valid. For example, they are of the wrong type or format.

Examples

In the following example, the SelectNodes(XPathNavigator, XPathNavigator, String) method is used to select the nodes in the first row of a Repeating Table control bound to group2. The GetContextNodes method is then used to return a collection of context nodes based on the current selection and the specified node. Finally, the code loops through the collection of context nodes and displays the name, inner XML, and value of each node.

// Create XPathNavigator and specify XPath for nodes.
XPathNavigator repeatingTableRow1 = 
   MainDataSource.CreateNavigator().SelectSingleNode(
   "/my:myFields/my:group1/my:group2[1]", NamespaceManager);

// Select nodes in specified XPathNavigator.
CurrentView.SelectNodes(repeatingTableRow1,repeatingTableRow1,"CTRL5");

// Get context nodes in selection.
XPathNodeIterator contextNodes = 
   CurrentView.GetContextNodes(repeatingTableRow1,"CTRL5");

// Loop through collection and display information.
foreach (XPathNavigator contextNode in contextNodes)
{
   MessageBox.Show(contextNode.Name);
   MessageBox.Show(contextNode.InnerXml);
   MessageBox.Show(contextNode.Value);
}
' Create XPathNavigator and specify XPath for nodes.
Dim repeatingTableRow1 As XPathNavigator  = _
   CreateNavigator().SelectSingleNode( _
   "/my:myFields/my:group1/my:group2[1]", NamespaceManager)

' Select nodes in specified XPathNavigator.
CurrentView.SelectNodes(repeatingTableRow1,repeatingTableRow1,"CTRL5")

' Get context nodes in selection.
Dim contextNodes As XPathNodeIterator = _
   CurrentView.GetContextNodes(repeatingTableRow1)

' Loop through collection and display information.
Dim contextNode As XPathNavigator
For Each contextNode In contextNodes
   MessageBox.Show(contextNode.Name)
   MessageBox.Show(contextNode.InnerXml)
   MessageBox.Show(contextNode.Value)
Next

Remarks

You can determine the ViewContext identifier for a control or group by opening the form template in Design mode, displaying the control's Properties dialog box, and then clicking the Advanced tab.

When the ViewContext identifier is specified, all of the XML nodes that have been specified to be selected must be within that context.

The XML nodes returned by the GetContextNodes method consists of a sequence of 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.

Note: The GetContextNodes method will not return nodes based on the current selection if used in the event handler for the Clicked event of a button in the view, because the focus is lost from the control that is intended to be in context. To avoid this behavior, use GetContextNodes from a custom task pane, menu, or toolbar.

This member 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.

This type or member can be accessed only from code running in forms opened in Microsoft InfoPath Filler.

Applies to

GetContextNodes()

Gets a reference to an XPathNodeIterator for iterating over the returned XML nodes in the current selection.

public:
 abstract System::Xml::XPath::XPathNodeIterator ^ GetContextNodes();
public abstract System.Xml.XPath.XPathNodeIterator GetContextNodes ();
abstract member GetContextNodes : unit -> System.Xml.XPath.XPathNodeIterator
Public MustOverride Function GetContextNodes () As XPathNodeIterator

Returns

An XPathNodeIterator that is populated with the nodes in the current selection.

Exceptions

The GetContextNodes method was called from an event handler for the Loading event.

Examples

In the following example, the GetContextNodes method is used to return a collection of context nodes based on the current selection to populate an XPathNodeIterator object variable.The code then loops through the collection of context nodes and displays the name, inner XML, and value of each node.

// Get context nodes in current selection.
XPathNodeIterator contextNodes = 
   CurrentView.GetContextNodes();

// Loop through collection and display information.
foreach (XPathNavigator contextNode in contextNodes)
{
   MessageBox.Show(contextNode.Name);
   MessageBox.Show(contextNode.InnerXml);
   MessageBox.Show(contextNode.Value);
}
' Get context nodes in current selection.
Dim contextNodes As XPathNodeIterator = _
   CurrentView.GetContextNodes(repeatingTableRow1)

' Loop through collection and display information.
Dim contextNode As XPathNavigator
For Each contextNode In contextNodes
   MessageBox.Show(contextNode.Name)
   MessageBox.Show(contextNode.InnerXml)
   MessageBox.Show(contextNode.Value)
Next

Remarks

The XML nodes returned by the GetContextNodes method consists of a sequence of nodes that are mapped from the view, corresponding to the selected XSL Transformation (XSLT) nodes.

If the selected nodes are bound to more than one control in the view, you must use the GetContextNodes(XPathNavigator, String) method instead which allows you to specify the ViewContext identifier of the control that is bound to the nodes you want to iterate over.

Note: The GetContextNodes method will not return nodes based on the current selection if used in the event handler for the Clicked event of a button in the view, because the focus is lost from the control that is intended to be in context. To avoid this behavior, use GetContextNodes from a custom task pane, menu, or toolbar.

This member 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.

This type or member can be accessed only from code running in forms opened in Microsoft InfoPath Filler.

Applies to