Table of contents
TOC
Collapse the table of content
Expand the table of content

CustomXMLNode.ReplaceChildSubtree Method (Office)

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

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

NameRequired/OptionalData TypeDescription
XMLRequiredStringRepresents the subtree to be added.
OldNodeRequiredCustomXMLNodeRepresents 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

Other resources

CustomXMLNode Object Members

© 2018 Microsoft