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

CustomXMLNode.Delete Method (Office)

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

Deletes the current node from the tree (including all of its children, if any exist).


expression. Delete

expression An expression that returns a CustomXMLNode object.


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


The following example demonstrates using various methods to add custom XML parts, select parts and nodes with different criteria, append child subtrees, and delete parts and nodes.

Sub ShowCustomXmlParts() 
    On Error GoTo Err 

    Dim cxps As CustomXMLParts 
    Dim cxp1 As CustomXMLPart 
    Dim cxp2 As CustomXMLPart 
    Dim cxn As CustomXMLNode 
    Dim cxns As CustomXMLNodes 
    Dim strXml As String 
    Dim strUri As String 

    With ActiveDocument 
        ' Example written for Word. 

        ' Adding a custom XML part. 
        .CustomXMLParts.Add "<custXMLPart />" 

        ' Add and then load from a file. 
        Set cxp1 = .CustomXMLParts.Add 
        cxp1.Load "c:\invoice.xml" 

        ' Returns the first custom XML part with the given root namespace. 
        Set cxp2 = .CustomXMLParts("urn:invoice:namespace")     '  

        ' Access all with a given root namespace; returns the entire collection. 
        Set cxps = .CustomXMLParts.SelectByNamespace("urn:invoice:namespace") 

        ' DOM-type operations. 
        ' Get the XML. 
        strXml = cxp2.XML 
        ' Get the root namespace 
        strUri = cxp2.NamespaceURI  
        ' Get nodes using XPath.                              
        Set cxn = cxp2.SelectSingleNode("//*[@quantity < 4]")  
        Set cxns = cxp2.SelectNodes("//*[@unitPrice > 20]") 
        ' Append a child subtree to the single node selected previously. 

        ' Delete custom XML part and node and its children. 

    End With 

    Exit Sub 

' Exception handling. Show the message and resume. 
        MsgBox (Err.Description) 
        Resume Next 
End Sub

See also


CustomXMLNode Object

Other resources

CustomXMLNode Object Members

© 2018 Microsoft