Inserts the specified subtree into the location just before the context node.

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.InsertSubtreeBefore(XML, NextSibling)

expression An expression that returns a CustomXMLNode object.

Parameters

Name Required/Optional Data Type Description
XML Required String Represents the subtree to be added.
NextSibling Optional CustomXMLNode Specifies the context node.

Remarks

If theparameter is not a child of the context node or if the operation would result in an invalid tree structure, the insertion is not performed and an error message is displayed.

Example
The following example adds a custom part and then finds a node in that part by using an XPath expression. The code then inserts a node after the found node.

Visual Basic for Applications
Dim cxp1 As CustomXMLPart Dim cxn As CustomXMLNode With ActiveDocument ' Add a custom xml part. .CustomXMLParts.Add "<invoice>" ' Returns the first custom xml part with the given root namespace. Set cxp1 = .CustomXMLParts("urn:invoice:namespace") ' Get nodes using XPath. Set cxn = cxp1.SelectSingleNode("//*[@supplier = "Contoso"]") ' Insert a node before the single node selected previously. cxn.InsertNodeAfter("discount", "urn:invoice:namespace") End With

See also:

NextSibling