4 Replies Latest reply on May 21, 2012 11:20 AM by Marcos Suárez

    File dialog box when importing XML?

    Angusdog Level 1

      Quick and hopefully easy question:

      What's the javascript format for selecting an XML file manually? I know it's not this:

       

      /* imports XML manually

      myDocument.importXML=File.openDialog("Choose the current XML file");

      */

       

      I have my project working well, but I've decided to get the user to manually select the XML in case they've downloaded a second version named (for example) data-1.xml and not data.xml. Then the onus is on them to select the most up-to-date XML and we can also name the xml with a datastamp.

       

      Thanks for this any all other help on this forum - I have little enough hair to pull out as it is...

       

      Simon.

        • 1. Re: File dialog box when importing XML?
          Angusdog Level 1

          And it's not this:

           

          // imports XML manually

          var myXMLFile=File.openDialog("Choose the current XML file");

          myDocument.importXML=myXMLFile;

          //

           

          Hmmm....

          • 2. Re: File dialog box when importing XML?
            csm_phil Level 4

            Hi Simon,

             

            Can you please try the below JS code and let me know if you have queries any.

             

             

            var myDoc = app.activeDocument;
            var myXMLFile=File.openDialog("Choose the current XML file");
            myDoc.importXML(File(myXMLFile));
            myDoc.xmlElements[0].placeXML(myDoc.pages[0].textFrames[0]);
            

             

             

            thx

            csm_phil

            • 3. Re: File dialog box when importing XML?
              Angusdog Level 1

              HI Phil,

               

              Lovely - the XML import works although I now need to get my head around XML story formatting. It's dropping all the XML into the first frame on the first page, which I understand to a degree, but also dropping the XML where I need it.

               

              The issue I have with the XML import is the automated document creation has been built around a sort of hybrid flow- and frame-based XML import. Some of the XML drops into a couple of text frames on the first page (creation date, sections etc), then the rest of the document autoflows onto however many pages it requires.

               

              It looks like I'll need to convert it to entirely flow-based XML import, which might be a bit of a head-scratch for me (being relatively new to this).

               

              Thanks very much. No doubt I'll be back on here with more questions but this is a huge help.

               

              <edit> I did 'fix' the XML, and it works a treat. The more I do, the more I understand.

               

              Regards,

               

              Simon.

              • 4. Re: File dialog box when importing XML?
                Marcos Suárez Level 1

                It does not work in CS4 ...
                How could it work?