Export (0) Print
Expand All

CustomXMLPart.AddNode Method

Office 2007
Adds a node to the XML tree.
Aa433519.vs_note(en-us,office.12).gif  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.AddNode(Parent, Name, NamespaceURI, NextSibling, NodeType, NodeValue)

expression   An expression that returns a CustomXMLPart object.

Parameters

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.

Remarks

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

Example

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

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



Community Additions

ADD
Show:
© 2014 Microsoft