Skip to main content
January 21, 2009
Question

Import XML [JS]

  • January 21, 2009
  • 4 replies
  • 1181 views
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
This topic has been closed for replies.

4 replies

Loic.Aigon
Legend
January 22, 2009
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.
January 22, 2009
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"));
}
Participant
January 22, 2009
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.
>
Loic.Aigon
Legend
January 21, 2009
Start trying this :
import into doc rather than app
You mistyped myFile (myFIle)

app.activeDocument.importXML(myFile, myXML);