SelectNodes Method

Microsoft Office InfoPath

Selects a range of nodes in a view based on the specified starting XML Document Object Model (DOM) node, the ending XML DOM node, and the view context.

expression.SelectNodes(ByRef pxnStartNode As XMLDOMNode, [ByVal varEndNode As Variant], [ByVal varViewContext As Variant])

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

pxnStartNode Required XMLDOMNode. The XML DOM node that begins the range.

varEndNode Optional Variant. The XML DOM node that ends the range. If not specified, only the starting XML DOM node will be used.

varViewContext Optional Variant. The ID of the control that is used for the context, which is an element with the specified view context of xd:CtrlId.

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 a view context is specified, all of the XML DOM nodes that are to be selected must be within that context.

If any of the arguments to the SelectNodes method are null or are not exposed in the view, the SelectNodes method will return an error. In addition, if there are more than one set of view elements which map to the same specified XML DOM nodes, within the specified view context, then the SelectNodes method will also return an error.

Example

In the following example, the SelectNodes method of the View object is used to set selection on a single item in the view, corresponding to the specified XML DOM node and then, using the GetSelectedNodes method of the View object, determines whether the selection has been successful by displaying information about the XML DOM node in a message box:

function SelectEmployee()
{
   var objXMLNodes;
   var objXMLNode;

   objXMLNode = XDocument.DOM.selectSingleNode("/employees/employee");
   XDocument.View.SelectNodes(objXMLNode);

   objXMLNodes = XDocument.View.GetSelectedNodes();
   if (objXMLNodes.Count > 0)
   {
      XDocument.UI.Alert(objXMLNodes(0).nodeName + "\n\n" + objXMLNodes(0).text);
   }
}