SelectSingleNode 方法 (Office) CustomXMLPartCustomXMLPart.SelectSingleNode method (Office)

选择自定义 XML 部件内与 XPath 表达式匹配的单个节点。Selects a single node within a custom XML part matching an XPath expression.

语法Syntax

表达式SelectSingleNode(XPath)expression.SelectSingleNode(XPath)

_表达式_一个返回**CustomXMLPart** 对象的表达式。expression An expression that returns a CustomXMLPart object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
XPathXPath 必需Required StringString 包含一个 XPath 表达式。Contains an XPath expression.

返回值Return value

CustomXMLNodeCustomXMLNode

示例Example

以下示例说明了添加自定义 XML 部件,选择具有命名空间 URI 的部件,然后在该部件内选择与 XPath 表达式匹配的节点。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

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.