Altova XMLSpy 2024 Enterprise Edition


The objects described in this section (Application API for Java) are obsolete from v2012 onwards.


For information about how to access the Application API from Java code, see the section: Programming Languages | Java.



The "SpyDoc doc = app.GetDocuments().OpenFile(...)" command parameter must be altered to suit your environment.


What the sample does:


Starts a new XMLSpy instance

Opens the Datasheet.xml file (alter the path here...)

Switches to the Enhanced Grid view

Appends a new child element called "NewChild" with the text value "NewValuE" element to the root element

Checks if the document is valid and outputs a message to the Java console

Quits and releases the XMLSpy application



import XMLSpyInterface.*;


public class TestSpyInterface


public TestSpyInterface() {}


public static void main(String[] args)


SpyApplication app = null;

SpyDoc oDoc = null;

SpyXMLData oData = null;

SpyXMLData oNewChild = null;




app = new SpyApplication();

app.ShowApplication( true );


oDoc = app.GetDocuments().OpenFile("C:\\FilePath\\OrgChart.xml", true );


// OrgChart.xml is in the folder C:\Documents and Settings\<username>\My Documents\Altova\XMLSpy2024. The filepath should be in

// the form: C:\\Documents and Settings\\Username\\Folder\\Filename.xml


if ( oDoc != null )



oData = oDoc.GetRootElement();

oNewChild = oDoc.CreateChild(SPYXMLDataKind.spyXMLDataElement);


oNewChild.SetName( "NewChild" );




if ( oDoc.IsValid() == false )


// is to be expected after above insertion

System.out.println( "!!!!!!validation error: " + oDoc.GetErrorString() );

System.out.println( "!!!!!!validation error: " + oDoc.GetErrorPos() );

System.out.println( "!!!!!!validation error: " + oDoc.GetBadData() );            








// Free any allocated resources by calling ReleaseInstance().

if ( oNewChild != null )



if ( oData != null )



if ( oDoc != null )



if ( app != null )






If you have difficulties compiling this sample, please try the following commands on the (Start | Run | cmd) command line. Please make sure you are currently in the folder that contains the sample java file.



javac -classpath c:\yourpathhere\XMLSpyInterface.jar



java -classpath c:\yourpathhere\XMLSpyInterface.jar testspyinterface

© 2018-2024 Altova GmbH