Altova XMLSpy 2024 Professional 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 :Pour XMLSpy 32-bit, le nom enregistré ou l'identificateur programmatique (ProgId) de l'objet COM est XMLSpy.Application. Pour XMLSpy 64-bit, le nom est XMLSpy_x64.Application. Néanmoins, n'oubliez pas que le programme d'appel accédera aux entrée de registre CLASSES dans sa propre ruche de registre, ou groupe (32-bit ou 64-bit). C'est pourquoi, si vous exécutez des scripts en utilisant l'invite de commande standard et Windows Explorer sur Windows 64-bit, les entrées de registre 64-bit seront accédées, et pointeront vers le XMLSpy 64-bit. Pour cette raison, si les deux XMLSpy 32-bit et 64-bit sont installés, une gestion spéciale est nécessaire afin de pouvoir appeler le XMLSpy 32-bit. Par exemple, si on part du principe que Windows Scripting Host est le programme d'appel, procéder comme suit :

 

1.Changer le répertoire actuel à C:\Windows\SysWOW64.

2.Dans la ligne de commande, saisir wscript.exe suivi du chemin vers le script que vous souhaitez exécuter, par exemple :

 

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

© 2017-2023 Altova GmbH