Table of contents
TOC
折叠目录
展开目录

CustomXMLPart.AddNode 方法 (办公室)CustomXMLPart.AddNode Method (Office)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

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

语法Syntax

表达式AddNode名称属性NextSibling节点类型( NodeValueexpression. AddNode( Parent, Name, NamespaceURI, NextSibling, NodeType, NodeValue )

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

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
ParentParent必需RequiredCustomXMLNodeCustomXMLNode代表应该在其下添加此节点的节点。如果添加属性,则该参数指示应该向其添加属性的元素。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.
名称Name可选OptionalStringString代表要添加的节点的基本名称。Represents the base name of the node to be added.
属性NamespaceURI可选OptionalStringString代表要追加的元素的命名空间。此参数需要追加节点类型msoCustomXMLNodeElementmsoCustomXMLNodeAttribute,否则它将被忽略。Represents the namespace of the element to be appended. This parameter is required to append nodes of type msoCustomXMLNodeElement or msoCustomXMLNodeAttribute, otherwise it is ignored.
NextSiblingNextSibling可选OptionalCustomXMLNodeCustomXMLNode代表应该成为新节点的下一个同级节点。如果未指定,则将节点添加到父节点的子节点的末尾。类型msoXMLNodeAttribute中添加的则忽略此参数。如果节点不是父的子级,则显示错误。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. This parameter is ignored for additions of type msoXMLNodeAttribute. If the node is not a child of the parent, an error is displayed.
节点类型NodeType可选OptionalMsoCustomXMLNodeTypeMsoCustomXMLNodeType指定要追加的节点的类型。如果未指定该参数,则假定其值为的类型msoCustomXMLNodeElementSpecifies the type of node to append. If the parameter is not specified, it is assumed to be of type msoCustomXMLNodeElement.
NodeValueNodeValue可选OptionalStringString用于为允许文本的那些节点追加的节点的值设置。如果该节点不允许文本,则将忽略该参数。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操作将导致树结构无效,则不执行追加,会显示一条错误消息。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

概念Concepts

CustomXMLPart 对象CustomXMLPart Object

其他资源Other resources

CustomXMLPart 对象成员CustomXMLPart Object Members

© 2018 Microsoft