Altova XMLSpy 2024 Professional Edition

The JScript listing below shows how to iterate through the open documents. It is assumed that you have already started the application and opened some documents as shown in the previous sections.

 

 

// go through all open documents using a JScript Enumerator
bRequiresSaving = false;
for (var iterDocs = new Enumerator(objSpy.Documents); !iterDocs.atEnd(); iterDocs.moveNext())
{
  if (iterDocs.item().IsModified)
     bRequiresSaving = true;
     
  var strErrorText = new Array(1);
  var nErrorNumber = new Array(1);
  var errorData = new Array(1);
 
  if (!iterDocs.item().IsValid(strErrorText, nErrorNumber, errorData))
  {
      var text = strErrorText;
     // access that XMLData object only if filled in
      if (errorData[0] != null)
        text += "(" + errorData[0].Name + "/" + errorData[0].TextValue + ")";
       
     WScript.Echo("Document \"" + iterDocs.item().Name +"\" validation error[" + nErrorNumber + "]: " + text);
  }
  else
  {
     // The COM call succeeded and the document is valid.
     WScript.Echo("Document \"" + iterDocs.item().Name + "\" is valid.");
  }
}
 
// go through all open documents using index-based access to the document collection
for (i = objSpy.Documents.Count; i > 0; i--)
  objSpy.Documents.Item(i).Close(false);

 

 

The JScript code listed above is available in the sample file DocumentAccess.js (see Example Files).

© 2017-2023 Altova GmbH