Altova XMLSpy 2024 Enterprise Edition

The code snippet below (from the AutomateXMLSpy example) lists the code for two event handlers. The AutomateXMLSpy example (see the file Form1.cs)  is located in the C# subfolder of the API Examples folder:



Windows 7, Windows 8, Windows 10, Windows 11



You can compile and run the project from within Visual Studio 2012/2013/2015/2017/2019/2022.


Code snippet


       // Event handler for OnDocumentOpened event

       private void handleOnDocumentOpened(XMLSpyLib.Document i_ipDocument)


           MessageBox.Show("Document " + i_ipDocument.Name + " was opened!");



       // Remember if the event handler is currently registered.

       private bool bEventHandlerIsRegistered = false;


       // Handler for button 'OnDocuemntOpened Event On/Off

       private void toggleOnDocumentOpenedEvent_Click(object sender, EventArgs e)


           if (XMLSpy != null)


               if (bEventHandlerIsRegistered)

                   XMLSpy.OnDocumentOpened -= new XMLSpyLib._IApplicationEvents_OnDocumentOpenedEventHandler(handleOnDocumentOpened);


                   XMLSpy.OnDocumentOpened += new XMLSpyLib._IApplicationEvents_OnDocumentOpenedEventHandler(handleOnDocumentOpened);


               bEventHandlerIsRegistered = !bEventHandlerIsRegistered;




© 2018-2024 Altova GmbH