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

CustomXMLPart.AddNode Method (Office)

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

Adds a node to the XML tree.


expression. AddNode( Parent, Name, NamespaceURI, NextSibling, NodeType, NodeValue )

expression An expression that returns a CustomXMLPart object.


NameRequired/OptionalData TypeDescription
ParentRequiredCustomXMLNodeRepresents the node under which this node should be added. If adding an attribute, the parameter denotes the element that the attribute should be added to.
NameOptionalStringRepresents the base name of the node to be added.
NamespaceURIOptionalStringRepresents the namespace of the element to be appended. This parameter is required to append nodes of type msoCustomXMLNodeElement or msoCustomXMLNodeAttribute, otherwise it is ignored.
NextSiblingOptionalCustomXMLNodeRepresents the node which should become the next sibling of the new node. If not specified, the node is added to the end of the parent node's children. This parameter is ignored for additions of type msoXMLNodeAttribute. If the node is not a child of the parent, an error is displayed.
NodeTypeOptionalMsoCustomXMLNodeTypeSpecifies the type of node to append. If the parameter is not specified, it is assumed to be of type msoCustomXMLNodeElement.
NodeValueOptionalStringUsed to set the value of the appended node for those nodes that allow text. If the node doesn't allow text, the parameter is ignored.


If the AddNode operation would result in an invalid tree structure, the append is not performed and an error message is displayed.


The following example demonstrates adding a node to a CustomXMLPart object.

Sub AddNodeCustomXmlParts() 

    Dim cxp1 As CustomXMLPart 
    Dim cxn As CustomXMLNode 

    With ActiveDocument 
        ' Add and populate a custom xml part 
        Set cxp1 = .CustomXMLParts.Add("<invoice />") 

        ' Set the parent node  
        Set cxn = cxp1.SelectSingleNode("/invoice") 

        ' Add a node under the parent node 
        cxp1.AddNode cxn, "upccode", "urn:invoice:namespace" 

    End With 

End Sub

See also


CustomXMLPart Object

Other resources

CustomXMLPart Object Members

© 2018 Microsoft