Partager via


XMLNode.RemoveChild, méthode

Supprime l'élément enfant spécifié du contrôle XMLNode.

Espace de noms :  Microsoft.Office.Tools.Word
Assembly :  Microsoft.Office.Tools.Word (dans Microsoft.Office.Tools.Word.dll)

Syntaxe

'Déclaration
Sub RemoveChild ( _
    childElement As XMLNode _
)
void RemoveChild(
    XMLNode childElement
)

Paramètres

Exemples

L'exemple de code suivant illustre les gestionnaires des événements AfterInsert et BeforeDelete. Le code affiche un message avant qu'un XMLNode ne soit supprimé du document et après qu'un XMLNode est ajouté au document. L'exemple utilise également la méthode RemoveChild pour supprimer un nœud et déclencher par programme l'événement BeforeDelete. Cet exemple suppose que le document actuel contient un XMLNode nommé CustomerNode qui contient un nœud enfant nommé CustomerDateNode.

Private Sub XMLNodeInsertAndDelete()
    Me.CustomerNode.RemoveChild(Me.CustomerDateNode.InnerObject)
End Sub

Private Sub XMLNode_BeforeDelete(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs) _
    Handles CustomerDateNode.BeforeDelete

    Dim tempNode As Microsoft.Office.Tools.Word.XMLNode = _
        CType(sender, Microsoft.Office.Tools.Word.XMLNode)
    If e.InUndoRedo Then
        MsgBox(tempNode.BaseName & " element is about to be " & _
            "deleted as a result of an undo or redo operation.")
    Else
        MsgBox(tempNode.BaseName & " element is about to be " & _
            "deleted.")
    End If
End Sub

Private Sub XMLNode_AfterInsert(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs) _
    Handles CustomerDateNode.AfterInsert

    Dim tempNode As Microsoft.Office.Tools.Word.XMLNode = _
        CType(sender, Microsoft.Office.Tools.Word.XMLNode)

    If e.InUndoRedo Then
        MsgBox(tempNode.BaseName & " element was " & _
            "inserted as a result of an undo or redo operation.")
    Else
        MsgBox(tempNode.BaseName & " element was inserted.")
    End If
End Sub
private void XMLNodeInsertAndDelete()
{
    this.CustomerDateNode.AfterInsert +=
        new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
        XMLNode_AfterInsert);

    this.CustomerDateNode.BeforeDelete +=
        new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
        XMLNode_BeforeDelete);

    this.CustomerNode.RemoveChild(this.CustomerDateNode.InnerObject);
}

void XMLNode_BeforeDelete(object sender, 
    Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
    Microsoft.Office.Tools.Word.XMLNode tempNode =
        (Microsoft.Office.Tools.Word.XMLNode)sender;

    if (e.InUndoRedo)
    {
        MessageBox.Show(tempNode.BaseName + " element is about to be " +
            "deleted as a result of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(tempNode.BaseName + " element is about to be " +
            "deleted.");
    }
}


void XMLNode_AfterInsert(object sender,
    Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
    Microsoft.Office.Tools.Word.XMLNode tempNode =
        (Microsoft.Office.Tools.Word.XMLNode)sender;

    if (e.InUndoRedo)
    {
        MessageBox.Show(tempNode.BaseName + " element was " +
            "inserted as a result of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(tempNode.BaseName + " element was inserted.");
    }
}

Sécurité .NET Framework

Voir aussi

Référence

XMLNode Interface

Microsoft.Office.Tools.Word, espace de noms