Events

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Programmers' Reference > Application API > Overview > Programming Languages > JScript >

Events

COM specifies that a client must register itself at a server for callbacks using the connection point mechanism. The automation interface for XMLSpy defines the necessary event interfaces. The way to connect to those events depends on the programming language you use in your client. The following code listing shows how this is done using JScript.

 

The method WScript.ConnectObject is used to receive events.

 

// The event-handler function
function DocEvent_OnBeforeCloseDocument(objDocument)
{
  WScript.Echo("Received event - before closing document");
}
 
// Create or connect to XMLSpy (or Authentic Desktop)
try
{
  // Create the environment and XMLSpy (or Authentic Desktop)
  objWshShell = WScript.CreateObject("WScript.Shell");
  objFSO = WScript.CreateObject("Scripting.FileSystemObject");
  objSpy = WScript.GetObject("", "XMLSpy.Application");
 
// If only Authentic Desktop is installed (and XMLSpy is not installed) use:
// objSpy = WScript.GetObject("", "AuthenticDesktop.Application")
 
}
catch(err)
  { WScript.Echo ("Can't create WScript.Shell object or XMLSpy"); }
 
// Create document object and connect to its events
objSpy.Visible = true;
majorVersionYear = objSpy.MajorVersion + 1998
docPath = objWshShell.ExpandEnvironmentStrings("%USERPROFILE%") + "\\Documents\\Altova\\XMLSpy" + majorVersionYear + "\\Examples\\ExpReport.xml";
objDoc = objSpy.Documents.OpenFile (docPath, false);
WScript.ConnectObject(objDoc, "DocEvent_");
 
// Keep running while waiting for the event
// In the meanwhile close this document in XMLSpy (or Authentic Desktop) manually
WScript.Echo ("Sleeping for 10 seconds ...");
WScript.Sleep (10000);
 
objDoc = null;
WScript.Echo ("Stopped listening for event");
objSpy.Quit();


© 2019 Altova GmbH