Share via


CustomXMLNode.ReplaceChildSubtree Method (Office)

Removes the specified node (and its subtree) from the main tree, and replaces it with a different subtree in the same location.

Syntax

expression .ReplaceChildSubtree(XML, OldNode)

expression An expression that returns a CustomXMLNode object.

Parameters

Name

Required/Optional

Data Type

Description

XML

Required

String

Represents the subtree to be added.

OldNode

Required

CustomXMLNode

Represents the child node to be replaced.

Remarks

If the operation would result in an invalid tree structure, the replacement operation 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 subtree of that node with another subtree.

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")     '  
         
    ' Get node using XPath expression.                              
    Set cxn = cxp1.SelectSingleNode("//*[@supplierID = 1]")  
 
    ' Replace one subtree and its children with another. 
   cxn.ReplaceChildSubtree("<rebates><rebate>0.10</rebate></rebates>", "//discounts")   
                 
 End With

See Also

Concepts

CustomXMLNode Object

CustomXMLNode Object Members