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

CustomXMLNode.InsertNodeBefore Method (Office)

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

Inserts a new node just before the context node in the tree.

Syntax

expression. InsertNodeBefore( Name, NamespaceURI, NodeType, NodeValue, NextSibling )

expression An expression that returns a CustomXMLNode object.

Parameters

NameRequired/OptionalData TypeDescription
NameOptionalStringRepresents the base name of the node to be added.
NamespaceURIOptionalStringRepresents the namespace of the element to be added. This parameter is required if adding nodes of type msoCustomXMLNodeElement or msoCustomXMLNodeAttribute, otherwise it is ignored.
NodeTypeOptionalMsoCustomXMLNodeTypeSpecifies the type of the node to be added. If the parameter is not specified, it is assumed to be a node of type msoCustomXMLNodeElement.
NodeValueOptionalStringUsed to set the value of the node to be added for those nodes that allow text. If the node doesn't allow text, the parameter is ignored.
NextSiblingOptionalCustomXMLNodeRepresents the context node.

Remarks

If the context node is not present when adding a node of type msoCustomXMLNodeElement, msoCustomXMLNodeComment, or msoCustomXMLNodeProcessingInstruction, the new node is added to the last child of the context node. 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 before 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 node using XPath.                              
   Set cxn = cxp1.SelectSingleNode("//*[@supplier = "Contoso"]")  

   ' Insert a node before the single node selected previously. 
    cxn.InsertNodeBefore("discount", "urn:invoice:namespace")   

 End With

See also

Concepts

CustomXMLNode Object

Other resources

CustomXMLNode Object Members

© 2018 Microsoft