Altova XMLSpy 2025 Enterprise Edition

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 VBScript.

 

The method WScript.ConnectObject is used to receive events.

 

To run this code, paste it into a file with .vbs extension, and either double-click in Windows Explorer, or run it from a command prompt.

 

' the event handler function
Function DocEvent_OnBeforeCloseDocument(objDocument)
  Call WScript.Echo("received event - before closing document")
End Function
 
' create or connect to XmlSpy
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objSpy = WScript.GetObject("", "XMLSpy.Application")
' If only Authentic is installed (and XMLSpy is not installed) use:
' Set objSpy = WScript.GetObject("", "AuthenticDesktop.Application")
' If only XMLSpy 64-bit is intalled, use:
' Set objSpy = WScript.GetObject("", "XMLSpy_x64.Application")
 
' create document object and connect to its events
objSpy.Visible = True
 
' Find out user's personal folder and locate one of the installed examples.
personalFolder = objWshShell.ExpandEnvironmentStrings("%UserProfile%")
majorVersionYear = objSpy.MajorVersion + 1998
xmlspyExamplesFolder = personalFolder & "\Documents\Altova\XMLSpy" & majorVersionYear  & "\Examples\"
docPath = xmlspyExamplesFolder & "ExpReport.xml"
 
' open a document
Set objDoc = objSpy.Documents.OpenFile (docPath, False)
Call WScript.ConnectObject(objDoc, "DocEvent_")
 
' keep running while waiting on the event
' in the meantime close the document in XMLSPY manually
Call WScript.Echo ("sleeping for 10 seconds ...")
Call WScript.Sleep (10000)
 
Set objDoc = Nothing
Call WScript.Echo ("stopped listening for event")
Call objSpy.Quit

 

 

 

Note:For 32-bit XMLSpy, the registered name, or programmatic identifier (ProgId) of the COM object is XMLSpy.Application. For 64-bit XMLSpy, the name is XMLSpy_x64.Application. Be aware, though, that the calling program will access the CLASSES registry entries in its own registry hive, or group (32-bit or 64-bit). Therefore, if you run scripts using the standard command prompt and Windows Explorer on 64-bit Windows, the 64-bit registry entries will be accessed, which point to the 64-bit XMLSpy. For this reason, if both XMLSpy 32-bit and 64-bit are installed, special handling is required in order to call the 32-bit XMLSpy. For example, assuming that Windows Scripting Host is the calling program, do the following:

 

1.Change the current directory to C:\Windows\SysWOW64.

2.At the command line, type wscript.exe followed by the path to the script that you would like to run, for example:

 

wscript.exe "C:\Users\...\Documents\Altova\StyleVision2025\StyleVisionExamples\API\JScript\start.js"wscript.exe "C:\Users\...\Documents\Altova\XMLSpy2025\Examples\API\JScript\start.js"

© 2018-2024 Altova GmbH