1 Reply Latest reply on Sep 11, 2009 9:01 AM by S Hopkins

    XML Importscript to InDesign?

    ma_gl

      Hello Forum,

      I'm just searching for a solution to import a few XML-files into InDesign.
      Each XML-file is about one theme.
      So it is much work to import each xml-file one by one into InDesign (up to 300 files).
      Do you know a possibility to import the whole XML-files by a java-script?
      I only found export-scripting, but no import.

      I'll be very, very glad, if you can help me!!

       

      Greetings,

        • 1. Re: XML Importscript to InDesign?
          S Hopkins Adobe Community Professional

          The big consideration in importing XML is setting the XML preferences correctly. For an append import you can modify the following function which requires a reference to the active document as its only parameter:

          function xmlAppendPrefs (docRef){

          var xmlPrefs = docRef.xmlImportPreferences;

          xmlPrefs.createLinkToXML = false;

          xmlPrefs.allowTransform = false;

          xmlPrefs.ImportStyle = XMLImportStyles.APPEND_IMPORT;

          xmlPrefs.repeatTextElements = false;

          xmlPrefs.importToSelected = false;

          xmlPrefs.ignoreWhitespace = true;

          xmlPrefs.ignoreUnmatchedIncoming = false;

          xmlPrefs.importCALSTablbes = false;

          xmlPrefs.importTextIntoTables = false;

          }

           

          Assuming you have an array of XML file references, you then iterate through the array to import the files. The next function makes sure that the fileRef reference passed is a file but does not check to make sure the file exists. The function expects a reference to the active document and the file reference (fileRef) as its parameters.

           

          function importXMLFile (docRef, fileRef) {

          try {

          if (fileRef instanceof File) {

          docRef.importXML(fileRef);

          } else {

          docRef.importXML(File(fileRef));

          }

          } catch (e) {

          throw (e);

          }

          }

           

          You will want to make sure that your XML files do not repeat the Root tag. If they all share the same similar structure, you should have no problem.

          For instance, if the file structures all begin with <story>, your structure will end up with <Root><story>story contents here</story><story>another story contents here</story></Root>.

          Hope this helps,

          Shirley Hopkins