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

Note
References to DTDs from custom XML parts are not supported. DTD references in custom XML parts will not resolve, and custom XML parts containing DTD references generate an exception when an attempt is made to save the file's content to a flat XML file.

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.

Visual Basic for Applications
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: