Application API of XMLSpy
The COM-based API of XMLSpy (also called the Application API from now on) enables other applications to use the functionality of XMLSpy. As a result, it is possible to automate a wide range of tasks, from validating an XML file to modifying complex XML content (with the XMLData interface).
XMLSpy and its Application API follow the common specifications for automation servers set out by Microsoft. It is possible to access the methods and properties of the Application API from common development environments, such as those using C#, C++, VisualBasic, and Delphi, and with scripting languages like JScript and VBScript.
Execution environments for the Application API
The Application API can be accessed from the following execution environments:
•External programs (described below and in the Overview part of this section)
•From within the built-in Scripting Editor of XMLSpy. For a description of the scripting environment, see the section, Scripting Editor.
•XMLSpy allows you to create and integrate your own plug-ins into the application using a special interface for plug-ins. A description of how to create plug-ins is given in the section IDE Plug-ins.
•Via an ActiveX Control, which is available if the integration package is installed. For more information, see the section ActiveX Integration.
External programs
In the Overview part of this section, we describe how the functionality of XMLSpy can be accessed and automated from external programs.
Using the Application API from outside XMLSpy requires an instance of XMLSpy to be started first. How this is done depends on the programming language used. See the section, Programming Languages, for information about individual languages.
Essentially, XMLSpy will be started via its COM registration. Then the Application object associated with the XMLSpy instance is returned. Depending on the COM settings, an object associated with an already running XMLSpy can be returned. Any programming language that supports creation and invocation of COM objects can be used. The most common of these are listed below.
•JScript and VBScript script files have a simple syntax and are designed to access COM objects. They can be run directly from a DOS command line or with a double click on Windows Explorer. They are best used for simple automation tasks.
•C# is a full-fledged programming language that has a wide range of existing functionality. Access to COM objects can be automatically wrapped using C#..
•C++ provides direct control over COM access but requires relatively larger amounts of code than the other languages.
•Java: Altova products come with native Java classes that wrap the Application API and provide a full Java look-and-feel.
•Other programming languages that make useful alternatives are: Visual Basic for Applications, Perl, and Python.
Programming points
The following limitations must be considered in your client code:
•Be aware that if your client code crashes, instances of XMLSpy may still remain in the system.
•Don't hold references to objects in memory longer than you need them, especially those from the XMLData interface. If the user interacts between two calls of your client, then there is no guarantee that these references are still valid.
•Don't forget to disable dialogs if the user interface is not visible.
•See Error handling in JScript (and in C# and Java) for details of how to avoid annoying error messages.
•Free references explicitly if you are using C# or C++.
This documentation
This documentation section about the Application API is broadly divided into two parts.
•The first part consists of an Overview, which describes the object model for the API and explains how the API is accessed via various programming languages.
•The second part is a reference section (Interfaces and Enumerations) that contains descriptions of the interface objects of the Application API.