5 Replies Latest reply on Jun 29, 2015 7:41 AM by Dirk Becker

    importXML not working

    rboyarov91

      I have a test import working when i explicitly open a template and import...

       

      var newDoc = app.documents.add();//open(File(TEMPLATE_EXTENSION));

      newDoc.importXML(File(XML_EXTENSION));

       

      yet when I open up a new doc and try to open up the same xml at the active one, nothing happens...

       

      var doc = app.activeDocument;

      doc.importXML(File(XML_EXTENSION));

       

      The xml is imported just fine when done through the file menu. I've played around with xmlViewPreferences and xmlImportPreferences but can't get it to work. I just want it to show up in the side panel with the tags available to be used.

        • 1. Re: importXML not working
          Level 1

          main(); 

          function main(){ 

          //xml -  import options 

          var myDocument = app.activeDocument; 

          var myXMLImportPreferences = myDocument.xmlImportPreferences; 

          myXMLImportPreferences.allowTransform = false; 

          myXMLImportPreferences.createLinkToXML = true; 

          myXMLImportPreferences.ignoreUnmatchedIncoming = false; 

          myXMLImportPreferences.ignoreWhitespace = false; 

          myXMLImportPreferences.importCALSTables = false; 

          myXMLImportPreferences.importStyle = XMLImportStyles.appendImport; 

          myXMLImportPreferences.importTextIntoTables = false; 

          myXMLImportPreferences.importToSelected = false; 

          myXMLImportPreferences.removeUnmatchedExisting = false; 

          myXMLImportPreferences.repeatTextElements = false; 

           

           

           

           

          //open  xml file   /*

          var lista = ""; 

          var _folder = Folder.selectDialog("Select the path...", ""),

              _files = _folder.getFiles("*.xml");

          for(var A=0;A<_files.length;A++)

              {

                      if (_files[A] != null)

              { 

                      _files[A].open("read", "text"); 

                      testq = _files[A].read(); 

                      _files[A].close(); 

                      } else 

                          return false; 

                      myDocument.importXML(File(_files[A]), false);

                      var myDocument = app.activeDocument;

                      myDocument.xmlElements.item(0).placeXML(myDocument.pages.item(0).textFrames.item(0));

                      document.textPreferences.smartTextReflow = true;

                      app.activeDocument.recompose();

           

           

              } 

           

           

          }

          • 2. Re: importXML not working
            rboyarov91 Level 1

            Unfortunately this didn't work. A note: I am using InDesign 2015. Setting any of the xmlImportPreferences makes the code break. I tried going without changing them and the file was read but never imported. Again it broke on-  myDocument.importXML(File(_files[A]), false);

            • 3. Re: importXML not working
              Level 1

              create text frame in the application file and run the script

              • 4. Re: importXML not working
                rboyarov91 Level 1

                I don't want to populate the document with the tags imported, I want them to show up on the side panel in a tag hierarchy where you can drag them in manually.  My problem is the side panel not showing up when I import the xml doc. 

                • 5. Re: importXML not working
                  Dirk Becker Level 4

                  app.select(app.activeDocument.xmlElements.item(0));