CustomXMLPart.SelectSingleNode method (Office)

Selects a single node within a custom XML part matching an XPath expression.

Syntax

expression.SelectSingleNode(XPath)

expression An expression that returns a CustomXMLPart object.

Parameters

Name Required/Optional Data type Description
XPath Required String Contains an XPath expression.

Return value

CustomXMLNode

Example

The following example demonstrates adding a custom XML part, selecting a part with a namespace URI, and then selecting a node within that part that matches an XPath expression.


Dim cxp1 As CustomXMLPart
Dim cxn As CustomXMLNode

' Add a custom XML part.
ActiveDocument.CustomXMLParts.Add ( _
    "<suppliers>" & _
    "<supplier ID='1'>Contoso</supplier>" & _
    "<supplier ID='2'>Wingtip Toys</supplier>" & _
    "</suppliers>")

' Return the last custom XML part added to the document.
Set cxp1 = ActiveDocument.CustomXMLParts(ActiveDocument.CustomXMLParts.Count)

' Get a node using XPath.
Set cxn = cxp1.SelectSingleNode("//supplier[@ID=1]")

' Display the node value 'Contoso'.
MsgBox cxn.NodeValue


See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.