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

CustomXMLNode.InsertSubtreeBefore Method (Office)

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

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


expression. InsertSubtreeBefore( XML, NextSibling )

expression An expression that returns a CustomXMLNode object.


NameRequired/OptionalData TypeDescription
XMLRequiredStringRepresents the subtree to be added.
NextSiblingOptionalCustomXMLNodeSpecifies the context node.


If the NextSibling parameter 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.


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.

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


CustomXMLNode Object

Other resources

CustomXMLNode Object Members

© 2018 Microsoft