4 Replies Latest reply on Jan 22, 2009 12:20 AM by Loic.Aigon

    Import XML [JS]

    Rajeev Kumar MIL
      Hi all,

      I am trying to import XML file into chosen template, please see below. I am not able to import XML file, please help me. After importing I want to save the indesign document on the location of XML file.

      var FilterID = "InDesign Template: *.indt";
      var FilterXML = "XML File: *.xml";
      var myFile = File.openDialog("Please choose InDesign Template", FilterID);//To choose InDesign template
      var myXML = File.openDialog("Please choose XML File", FilterXML);
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
      var myDoc = app.open(myFile);
      //app.importXML(myFIle, myXML);

      Thanks
        • 1. Re: Import XML [JS]
          Loic.Aigon Adobe Community Professional
          Start trying this :
          import into doc rather than app
          You mistyped myFile (myFIle)

          app.activeDocument.importXML(myFile, myXML);
          • 2. Re: Import XML [JS]
            Change
            app.importXML(myFIle, myXML);
            to
            myDoc.importXML(myXML);

            Lin

            > -----Original Message-----
            > From: rajeevkumar [mailto:member@adobeforums.com]
            > Sent: Wednesday, January 21, 2009 4:45 AM
            > To: adobe.scripting.indesign@adobeforums.com
            > Subject: Import XML [JS]
            >
            > A new discussion was started by rajeevkumar in
            >
            > InDesign Scripting --
            > Import XML [JS]
            >
            > Hi all,
            >
            > I am trying to import XML file into chosen template, please see below.
            > I am not able to import XML file, please help me. After importing I
            > want to save the indesign document on the location of XML file.
            >
            > var FilterID = "InDesign Template: *.indt";
            > var FilterXML = "XML File: *.xml";
            > var myFile = File.openDialog("Please choose InDesign Template",
            > FilterID);//To choose InDesign template
            > var myXML = File.openDialog("Please choose XML File", FilterXML);
            > app.scriptPreferences.userInteractionLevel =
            > UserInteractionLevels.neverInteract;
            > var myDoc = app.open(myFile);
            > //app.importXML(myFIle, myXML);
            >
            > Thanks
            >
            >
            > ________________________________
            >
            > View/reply at Import XML [JS]
            >
            > Replies by email are OK.
            > Use the unsubscribe
            >
            form
            > to cancel your email subscription.
            >
            • 3. Re: Import XML [JS]
              Rajeev Kumar MIL Level 1
              Hi All,

              Thanks, I have already done that. Now I want to save InDesign document. at present if I am saving the file then it shows .xml.indd I want to remove .xml from the file name while saving.

              var FilterID = "InDesign Template: *.indt";
              var FilterXML = "XML File: *.xml";
              var myFile = File.openDialog("Please choose InDesign Template", FilterID);//To choose InDesign template
              var myXML = File.openDialog("Please choose XML File", FilterXML);
              var myXMLName = myXML.fielName;
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
              var myDoc = app.open(myFile);
              myDoc.xmlElements.item(0).importXML(File(myXML));

              if(app.activeDocument.saved == false)
              {
              app.activeDocument.save(new File(myXML+".indd"));
              }
              • 4. Re: Import XML [JS]
                Loic.Aigon Adobe Community Professional
                Hi
                I use this approach but they may be a better way :

                var myXMLFolder = File(myXML).parent;
                var myXMLName = myXML.name;
                ...
                if(app.activeDocument.saved == false)
                {
                app.activeDocument.save(new File(myXMLFolder+"/"+myXMLName.split(".xml")[0]+".indd"));
                }

                //myXMLName.split(".xml")[0] return first part of the name
                //I can't do myXML.split(".xml") so I had to reconstruct the path
                //Hence I needed to know the file parent folder.