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

CustomXMLNode.ReplaceChildNode 方法 (办公室)CustomXMLNode.ReplaceChildNode Method (Office)

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

删除指定的子节点 (及其子树) 从主树中,并将它替换为相同的位置中的其他节点。Removes the specified child node (and its subtree) from the main tree, and replaces it with a different node in the same location.

语法Syntax

表达式ReplaceChildNodeOldNode名称属性节点类型( NodeValueexpression. ReplaceChildNode( OldNode, Name, NamespaceURI, NodeType, NodeValue )

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

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
OldNodeOldNode必需RequiredCustomXMLNodeCustomXMLNode代表要替换的子节点。Represents the child node to be replaced.
名称Name可选OptionalStringString代表要添加的元素的基本名称。Represents the base name of the element to be added.
属性NamespaceURI可选OptionalStringString表示要添加的元素的命名空间。此参数是必需的如果添加节点类型msoCustomXMLNodeElementmsoCustomXMLNodeAttribute,否则它将被忽略。Represents the namespace of the element to be added. This parameter is required if adding nodes of type msoCustomXMLNodeElement or msoCustomXMLNodeAttribute, otherwise it is ignored.
节点类型NodeType可选OptionalMsoCustomXMLNodeTypeMsoCustomXMLNodeType指定要添加的节点的类型。如果未指定该参数,则假定其值为的类型msoCustomXMLNodeElementSpecifies the type of node to add. If the parameter is not specified, it is assumed to be of type msoCustomXMLNodeElement.
NodeValueNodeValue可选OptionalStringString用于为允许文本的那些节点添加的节点的值设置。如果该节点不允许文本,则将忽略该参数。Used to set the value of the node to be added for those nodes that allow text. If the node doesn't allow text, the parameter is ignored.

注解Remarks

如果_OldNode_参数不是上下文节点的子节点,或者操作将导致树结构无效,则不执行替换并显示一条错误消息。此外,在已添加的节点存在的情况下,则不执行替换并显示一条错误消息。If the OldNode parameter is not a child of the context node or if the operation would result in an invalid tree structure, the replacement is not performed and an error message is displayed. In addition, in a case where the node to be added already exists, the replacement is not performed and an error message is displayed.

示例Example

以下示例选择一个自定义部件,然后选择该部件中的一个节点。代码然后将该节点的子节点替换为其他节点。The following example selects a custom part and then a node in that part. The code then replaces a child of that node with another node.

Dim cxp1 As CustomXMLPart 
Dim cxn As CustomXMLNode 

With ActiveDocument 

   ' Return the first custom xml part with the given root namespace. 
   Set cxp1 = .CustomXMLParts("urn:invoice:namespace")     '  

   Set cxn = cxp1.SelectSingleNode("//*[@supplierID = 1]")  

   ' Replace a child node. 
    cxn.ReplaceChildNode(cxn.SelectSingleNode("//discount", "rebate")   

End With

另请参阅See also

概念Concepts

CustomXMLNode 对象CustomXMLNode Object

其他资源Other resources

CustomXMLNode 对象成员CustomXMLNode Object Members

© 2018 Microsoft