Altova XMLSpy 2024 Professional Edition

Der Befehlsparameter "SpyDoc doc = app.GetDocuments().OpenFile(...)" muss für Ihre Umgebung angepasst werden.

 

Das Beispiel führt folgende Schritte durch:

 

Es startet eine neue XMLSpy-Instanz

Es öffnet die Datei Datasheet.xml (ändern Sie den Pfad hier...)

Es wechselt in die Grid-Ansicht

Es hängt ein neues Child-Element namens "NewChild" mit dem Textwertelement "NewValuE" an das Root-Element an

Es überprüft, ob das Dokument gültig ist und gibt eine Meldung an die Java-Konsole aus

Es schließt die XMLSpy-Applikation und gibt diese frei

 

 

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;

 

try

{

app = new SpyApplication();

app.ShowApplication( true );

 

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

 

// OrgChart.xml is in the folder C:\Dokumente und Einstellungen\<Benutzer>\Eigene Dokumente\Altova\XMLSpy2024. The filepath should be in

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

 

if ( oDoc != null )

{

oDoc.SwitchViewMode(SPYViewModes.spyViewGrid);

oData = oDoc.GetRootElement();

oNewChild = oDoc.CreateChild(SPYXMLDataKind.spyXMLDataElement);

 

oNewChild.SetName( "NewChild" );

oNewChild.SetTextValue("newVaLuE");

oData.AppendChild(oNewChild);

 

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() );            

}

}

 

app.Quit();

}

finally

{

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

if ( oNewChild != null )

oNewChild.ReleaseInstance();

 

if ( oData != null )

oData.ReleaseInstance();

 

if ( oDoc != null )

oDoc.ReleaseInstance();

 

if ( app != null )

app.ReleaseInstance();

}

}

}

 

Wenn Sie Probleme haben, dieses Beispiel zu kompilieren, versuchen Sie bitte in der Befehlszeile (Start | Ausführen | cmd) die folgenden Befehle. Stellen Sie vorher sicher, dass Sie sich gerade in dem Ordner befinden, der die Java-Beispieldatei enthält.

 

Kompilierung

javac -classpath c:\IhrPfadhier\XMLSpyInterface.jar testspyinterface.java

 

Ausführung

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

© 2017-2023 Altova GmbH