Compartir a través de


DocumentBase.XMLAfterInsert Event

Definition

Occurs when a user adds a new XML element to a document. If more than one element is added to the document at the same time (for example, when cutting and pasting XML), the event is raised for each element that is inserted.

public:
 event Microsoft::Office::Interop::Word::DocumentEvents2_XMLAfterInsertEventHandler ^ XMLAfterInsert;
public event Microsoft.Office.Interop.Word.DocumentEvents2_XMLAfterInsertEventHandler XMLAfterInsert;
member this.XMLAfterInsert : Microsoft.Office.Interop.Word.DocumentEvents2_XMLAfterInsertEventHandler 
Public Custom Event XMLAfterInsert As DocumentEvents2_XMLAfterInsertEventHandler 

Event Type

Examples

The following code example demonstrates event handlers for the XMLAfterInsert and XMLBeforeDelete events. The code displays a message before an XMLNode is deleted from the document and after an XMLNode is added to the document. To test this code example, use the XML Structure task pane to add XML elements to the document, and then experiment with the Undo Typing and Redo Typing options on the Edit menu. This example assumes that the current document is mapped to a valid XML schema. To use this example, run it from the ThisDocument class in a document-level project.

private void DocumentXMLBeforeAndAfterInsert()
{
    this.XMLAfterInsert +=
        new Word.DocumentEvents2_XMLAfterInsertEventHandler(
        ThisDocument_XMLAfterInsert);

    this.XMLBeforeDelete +=
        new Word.DocumentEvents2_XMLBeforeDeleteEventHandler(
        ThisDocument_XMLBeforeDelete);
}

void ThisDocument_XMLBeforeDelete(Word.Range DeletedRange,
    Word.XMLNode OldXMLNode, bool InUndoRedo)
{
    if (InUndoRedo)
    {
        MessageBox.Show(OldXMLNode.BaseName +
            " element is about to be deleted as a result" +
            " of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(OldXMLNode.BaseName +
            " element is about to be deleted.");
    }
}

void ThisDocument_XMLAfterInsert(Word.XMLNode NewXMLNode,
    bool InUndoRedo)
{
    if (InUndoRedo)
    {
        MessageBox.Show(NewXMLNode.BaseName + " element was " +
            "inserted as a result of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(NewXMLNode.BaseName + " element was inserted.");
    }
}
Private Sub DocumentXMLBeforeAndAfterInsert()
    AddHandler Me.XMLAfterInsert, AddressOf ThisDocument_XMLAfterInsert
    AddHandler Me.XMLBeforeDelete, AddressOf ThisDocument_XMLBeforeDelete
End Sub 

Private Sub ThisDocument_XMLBeforeDelete(ByVal DeletedRange As Word.Range, ByVal OldXMLNode As Word.XMLNode, ByVal InUndoRedo As Boolean)
    If InUndoRedo Then
        MessageBox.Show(OldXMLNode.BaseName & " element is about to be deleted as a result" _
            & " of an undo or redo operation.")
    Else
        MessageBox.Show(OldXMLNode.BaseName & " element is about to be deleted.")
    End If
End Sub

Private Sub ThisDocument_XMLAfterInsert(ByVal NewXMLNode As Word.XMLNode, ByVal InUndoRedo As Boolean)
    If InUndoRedo Then
        MessageBox.Show(NewXMLNode.BaseName & " element was " & "inserted as a result " _
            & "of an undo or redo operation.")
    Else
        MessageBox.Show(NewXMLNode.BaseName & " element was inserted.")
    End If
End Sub

Applies to