CustomXMLNode. hasChildNodes,, méthode (bureau)CustomXMLNode.HasChildNodes method (Office)

Renvoie la valeur True si le nœud d'élément actif possède des nœuds d'éléments enfants.Gets True if the current element node has child element nodes.

SyntaxeSyntax

expression. HasChildNodes,expression.HasChildNodes

expression Expression qui renvoie un objet CustomXMLNode .expression An expression that returns a CustomXMLNode object.

Valeur renvoyéeReturn value

BooléenBoolean

RemarquesRemarks

Cette méthode renvoie toujours la valeur false lorsque l'élément CustomXMLNode n'est pas un nœud de type msoCustomXMLNodeElement.This method will always return False when CustomXMLNode isn't of node type msoCustomXMLNodeElement.

ExempleExample

L'exemple suivant illustre l'utilisation de différentes méthodes pour ajouter des parties XML personnalisées, sélectionner des parties et des nœuds avec différents critères, ajouter des sous-arborescences enfants, tester si la sous-arborescence a bien été ajoutée et supprimer des parties et des nœuds.The following example demonstrates using various methods to add custom XML parts, select parts and nodes with different criteria, append child subtrees, test whether the subtree was successfully added, 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. 
        cxn.AppendChildSubtree("<discounts><discount>0.10</discount></discounts>")   
 
         ' Tell user that the child subtree was added. 
         If  cxn.HasChildNodes then 
            MsgBox("The 'Discounts' nodes were added.")  
         Else 
            MsgBox("The 'Discounts' nodes were not added.")  
         End If          
         
        ' Delete custom XML part and node and its children. 
        cxp2.Delete 
        cxn.Delete 
 
                 
    End With 
     
    Exit Sub 
                 
' Exception handling. Show the message and resume. 
Err: 
        MsgBox (Err.Description) 
        Resume Next 
End Sub 

Voir aussiSee also

Assistance et commentairesSupport and feedback

Avez-vous des questions ou des commentaires sur Office VBA ou sur cette documentation ?Have questions or feedback about Office VBA or this documentation? Consultez la rubrique concernant l’assistance pour Office VBA et l’envoi de commentaires afin d’obtenir des instructions pour recevoir une assistance et envoyer vos commentaires.Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.