xml spy
Previous  Top  Next
Main scripting features

With the introduction of the COM API, the possibilities of XMLSpy became substantially expanded. It is the combination of common programming techniques using functions, recursions, global variables, error handling and so on, that gives the user the ability to deal with complex problems, to automate repetitive jobs or to realize completely new tasks. The scripting environment is the tool for creating and organizing these scripts.

Macros
Macros are used to implement complex or repetitive tasks and for direct user input via forms (dialogs). Macros don't have parameters and return values. It is possible to access all variables and functions which are declared in the global declarations and to display forms. Please see "How to write a macro" for a simple example. See also "Calling macros from XMLSpy".

Events
Events are a powerful way to react to user input and modify the behaviour of XMLSpy. All scripting code of an event is executed immediately, and gives you the ability to directly influence on the users handling of XMLSpy.

Most events have parameters which inform the script about the currently modified data. The return value informs the application how to continue its own processing (eg. forbid editing). See How to handle an event to learn more about the implementation of events.

Forms
Dialog boxes enable your scripts and XMLSpy to interact with the user. You are free to add any type of control to your forms. These controls use their own event handlers for the implementation of their functionality. A list of supported events for the selected control appears in the Property Sheet on the "Events" page. See "How to create a form" for a description of creating forms.

Programming details

1.Because macros don't have parameters or return values, a function header should not exist in the macro implementation.  
 
2.Event handlers need function headers with the correct spelling of the event name, or the event handler won't get called.  
 
3.It is possible to declare local variables and helper functions within macros and event handlers.  
Example:  
 
   //return value: true allows editing  
   //              false forbids editing  
 
   var txtLocal;  
 
   function Helper()  
   {  
      txtMessage = txtLocal;  
      Application.ShowForm("MsgBox");  
   }  
 
   function On_BeforeStartEditing(objXMLData)  
   {  
      txtLocal = "On_BeforeStartEditing()";  
      Helper();  
   }  
 
4.Recursive functions are supported. The function DeleteXMLElements() from "How to create a Form" calls itself recursively.  
 
5.A form can display another form with the function Application.ShowForm().  
 
6.Out-parameters from methods of the XMLSpy API require special variables in JavaScript.  
Example:  
 
   // use JavaScript method to access out-parameters  
   var strError = new Array(1);  
   var nErrorPos = new Array(1);  
   var objBadData = new Array(1);  
 
   bOK = objDoc.IsValid(strError,nErrorPos,objBadData);  
 
7.While a macro is executed, event handlers from XMLSpy are not processed.  

Previous  Top  Next

⌐ 2002 Altova