Activer JavaScript pour consulter ce site.

Altova XMLSpy 2020 Enterprise Edition

A demo project that illustrates scripting with XMLSpy is available at the following path: C:\Users\<user>\Documents\Altova\XMLSpy2020\Examples\SampleScripts.asprj. This scripting project consists of a few macros and a Windows form.

 

 

To load the scripting project into Scripting Editor:

1.On the Tools menu, click Scripting Editor.

2.Click Open and browse for the SampleScripts.asprj file from the path above.

 

The project contains several macros in the "Macros" directory.

 

Macro

Description

AddMacroMenu

This macro adds a new menu item to XMLSpy, by invoking the Application.AddMacroMenuItem method of the COM API. The first argument of the AddMacroMenuItem method is the name of the macro to be added (in this example, "CloseAllButActiveDoc") and the second argument is the display text for the menu item.

 

Whenever this macro is run, a new menu command called "CloseAllButActiveDoc") is added under the Tools menu. To clear macro menu items created previously, either restart XMLSpy or create a macro that calls the Application.ClearMacroMenu API method.

CloseAllButActiveDocument

When executed, the macro iterates though the currently open documents in XMLSpy and closes all of them, except for the active document.

SearchPath

This macro displays a form that lets users perform search for files within the current project. The form is available in the "Forms" directory, where you can view its design and the associated event handlers.

 

The GetAllPathsFromProject() method returns all the file paths that belong to the currently opened project, as an array. The definition of this method is in the GlobalDeclarations script of the project. The InsertStringInArrayUnique method ensures that only unique paths are added to the array. Next, the form is initialized with CreateForm. Finally, the array is converted to a .NET type with the help of the CLR.Create method and the form is populated with the resulting ArrayList collection.

 

The Open button of the form has a handler that calls the Application.Documents.OpenFile API method to open the currently selected file.

 

 

To enable the scripting project as global XMLSpy scripting project:

1.On the Tools menu, click Options.

2.Click the Scripting tab.

3.Under "Global scripting project file", click Browse and select the SampleScripts.asprj file from the path above.

4.This scripting project does not have auto-macros and application event handlers; therefore, you don't need to select either the Run auto-macros... or Process events check boxes.

5.Click Apply.

 

At this stage, several new menu items (one for each macro) become available under the Tools | Macros menu.

 

 

To run the "SearchPath" macro:

1.Open an XMLSpy project that contains several files (in this example, C:\Users\<user>\Documents\Altova\XMLSpy2020\Examples\Examples.spp).

2.On the Tools menu, click Macros, and then click Search Path.

3.Type the search term (in this example, ".xml").

scr_sample_xmlspy

As shown above, all file names that contain the search term are now listed. You can click any element in the list, and then click Open to display it in the main editor.

Created with Help+Manual 7 and styled with Premium Pack Version 3 © by EC Software