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

将节点添加到 XML 树。Adds a node to the XML tree.

语法Syntax

表达式AddNode(ParentNameNamespaceURINextSiblingNodeTypeNodeValue)expression.AddNode (Parent, Name, NamespaceURI, NextSibling, NodeType, NodeValue)

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

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
ParentParent 必需Required CustomXMLNodeCustomXMLNode 代表应该在其下添加此节点的节点。Represents the node under which this node should be added. 如果添加属性,则该参数指示应该向其添加属性的元素。If adding an attribute, the parameter denotes the element that the attribute should be added to.
NameName 可选Optional 字符串String 代表要添加的节点的基本名称。Represents the base name of the node to be added.
NamespaceURINamespaceURI 可选Optional 字符串String 代表要追加的元素的命名空间。Represents the namespace of the element to be appended. 此参数是追加类型msoCustomXMLNodeElementmsoCustomXMLNodeAttribute的节点所必需的;否则, 它将被忽略。This parameter is required to append nodes of type msoCustomXMLNodeElement or msoCustomXMLNodeAttribute; otherwise, it is ignored.
NextSiblingNextSibling 可选Optional CustomXMLNodeCustomXMLNode 代表应该成为新节点的下一个同级项的节点。Represents the node which should become the next sibling of the new node. 如果未指定, 则将节点添加到父节点的子节点的末尾。If not specified, the node is added to the end of the parent node's children. 如果添加 msoXMLNodeAttribute 类型的节点,则忽略此参数。This parameter is ignored for additions of type msoXMLNodeAttribute. 如果该节点不是父节点的子节点,则显示一个错误。If the node is not a child of the parent, an error is displayed.
NodeTypeNodeType 可选Optional MsoCustomXMLNodeTypeMsoCustomXMLNodeType 指定要追加的节点的类型。Specifies the type of node to append. 如果未指定该参数,则假定节点类型为 msoCustomXMLNodeElementIf the parameter is not specified, it is assumed to be of type msoCustomXMLNodeElement.
NodeValueNodeValue 可选Optional 字符串String 用于为允许文本的那些节点设置所追加节点的值。Used to set the value of the appended node for those nodes that allow text. 如果该节点不允许文本, 则忽略该参数。If the node doesn't allow text, the parameter is ignored.

说明Remarks

如果AddNode操作将导致树结构无效, 则不执行 append 操作并显示一条错误消息。If the AddNode operation would result in an invalid tree structure, the append is not performed and an error message is displayed.

示例Example

以下示例说明了如何将节点添加到 CustomXMLPart 对象。

The following example demonstrates adding a node to a CustomXMLPart object.

Sub AddNodeCustomXmlParts() 
 
    Dim cxp1 As CustomXMLPart 
    Dim cxn As CustomXMLNode 
     
    With ActiveDocument 
        ' Add and populate a custom xml part 
        Set cxp1 = .CustomXMLParts.Add("<invoice />") 
         
        ' Set the parent node  
        Set cxn = cxp1.SelectSingleNode("/invoice") 
         
        ' Add a node under the parent node 
        cxp1.AddNode cxn, "upccode", "urn:invoice:namespace" 
 
    End With 
     
End Sub

另请参阅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.