Altova XMLSpy 2024 Enterprise Edition

Importing data from a text file is similar to the import from a database. You must use other interfaces (described in steps 1 to 3 below) with different methods and properties:


1.Use a TextImportExportSettings object and set the properties: The method Application.GetTextImportExportSettings returns a new object to specify a text file for import: objImpSettings = objSpy.GetTextImportExportSettings(); You have to set at least the ImportFile property to the path of the file for the import. Another important property is HeaderRow. Set it to False if the text file does not contain a leading line as a header row: objImpSettings.ImportFile = strExampleFolder + "Tutorial\\Shapes.txt";

2.Call Application.GetTextImportElementList to get a collection of all columns inside the text file: objElementList = objSpy.GetTextImportElementList(objImpSettings);

3.Start the import with Application.ImportFromText: objImpDocFromText = objSpy.ImportFromText(objImpSettings,objElementList);



  // specify the source of data import
  objImpSettings = objSpy.GetTextImportExportSettings();
  objImpSettings.ImportFile = strExampleFolder + "Tutorial\\Shapes.txt";
  objImpSettings.HeaderRow = false;
  // column filter
  objElementList = objSpy.GetTextImportElementList(objImpSettings);
  // import into a new XML file
  objImpDocFromText = objSpy.ImportFromText(objImpSettings,objElementList);
  WScript.Echo("Error importing from text file.\n\n" +
                    "Error: " + (err.number & 0xffff) + "\n" +
                    "Description: " + err.description);



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

© 2018-2024 Altova GmbH