다음을 통해 공유


DocumentBase.XMLAfterInsert 이벤트

사용자가 문서에 새 XML 요소를 추가할 때 발생합니다.XML을 잘라내어 붙여넣을 때처럼 동시에 둘 이상의 요소가 문서에 추가되면 삽입되는 각 요소에 대해 이벤트가 발생합니다.

네임스페이스:  Microsoft.Office.Tools.Word
어셈블리:  Microsoft.Office.Tools.Word.v4.0.Utilities(Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

구문

‘선언
Public Event XMLAfterInsert As DocumentEvents2_XMLAfterInsertEventHandler
public event DocumentEvents2_XMLAfterInsertEventHandler XMLAfterInsert

예제

다음 코드 예제에서는 XMLAfterInsert 및 XMLBeforeDelete 이벤트의 이벤트 처리기를 보여 줍니다.코드에서는 XMLNode가 문서에서 삭제되기 전과 XMLNode가 문서에 추가된 후 메시지를 표시합니다.이 코드 예제를 테스트하려면 XML 구조 작업창을 사용하여 문서에 XML 요소를 추가한 다음 편집 메뉴의 입력 취소입력 다시 실행 옵션을 사용해 보십시오.이 예제에서는 현재 문서가 유효한 XML 스키마에 매핑된다고 가정합니다.이 예제를 사용하려면 문서 수준 프로젝트 ThisDocument 클래스에서 실행하십시오.

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
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.");
    }
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

DocumentBase 클래스

Microsoft.Office.Tools.Word 네임스페이스