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
|
| メモ: | 32-ビット XMLSpy では、登録された名前、または COM オブジェクトのプログラム識別子 (ProgId) は以下の通りです:MapForce.ApplicationXMLSpy.Application。64-ビット XMLSpy では、名前は以下の通りです:MapForce_x64.ApplicationXMLSpy_x64.Application。プログラムの呼び出しは自身のレジストリハイブ、またはグループ (32-bit または 64-bit)内の CLASSES レジストリエントリにアクセスすることに注意してください。ですから、標準のコマンドプロンプトと上 64-bit Windows の Windows Explorerを使用してスクリプトを実行すると、 64-ビット XMLSpy. を指す 64-ビットレジストリエントリにアクセスされます。この理由のため、 XMLSpy 32-ビットと 64-ビットの両方がインストールされている場合、 32-ビット XMLSpy. を呼び出すために特別な処理が必要になります。例えば、スクリプトホストがプログラムを呼び出す場合以下を行います: |
1.ディレクトリを C:\Windows\SysWOW64 に変更します。
2.コマンドライン上で wscript.exe を入力し実行するスクリプトパスを以下のように入力します:
wscript.exe "C:\Users\...\Documents\Altova\StyleVision2021\StyleVisionExamples\API\JScript\start.js"wscript.exe "C:\Users\...\Documents\Altova\XMLSpy2021\Examples\API\JScript\start.js"
|