Skip to main content
Participating Frequently
October 8, 2009
Answered

How to edit xml link?

  • October 8, 2009
  • 1 reply
  • 5017 views

First a few words about my context:

I received a layout made on a CS3 version of InDesign. Now I am trying to create a procedure to automate the production of several pdf based on this layout. Manually the process would be to open the layout; edit the xml link with each xml source and create a corresponding pdf...

First issue:

In CS4 when I want to manually edit the xml link, the opened dialog prevent me (xml files are in gray) to select xml files, is it a well-known issue? How can I avoid it?

Second question:

How to edit the xml link from script?

Last question - applescript question - :

How to skip application dialogs? Like "This document miss some links, would you continue?"

If you'd be able to help me, thanks in advance!

This topic has been closed for replies.
Correct answer Loic.Aigon

> I am not skilled at all with applescript. There is a lot of very good applescripters around here. You may refer to ADobe scripts examples, it's quite sure there is a relink example in it.

So I will try your javascript I think it's possible to call javascripts from applescript. I hope actually because there is no relink example with InDesign CS4.

Thanks again


There is a piece of code found on the net :

tell document 1 of application "Adobe InDesign CS3"
relink thisItemLink to someFileReference
update thisItemLink
end

1 reply

Loic.Aigon
Legend
October 8, 2009

Hi,

Depending on your needs, you may choose to

Manually :

1. Label an element of the layout (ex: a graphic frame labeled "Image");

2. Install xmljs library which is very cumfy to deal with XML without loading xml into Indesign.

Via scripting :

3. Process through the xml with the library and get back the datas your need (a picture file path for example)

4. Open the indesign document and proceed like this :

- Duplicates page one

- Proceed to changes on this duplicated page (graphic changes)

- Set the pdfExportPreferences.pageRange to the page name (as String);

- Export the page your document as PDF

- Continue

5. Either save or not the document, close it.

xmljs : http://xmljs.sourceforge.net/

But that's not applescript...

A+ Loic

poxdAuthor
Participating Frequently
October 8, 2009

Hi and thanks for your answer.

My issue is not about xml but moreover InDesign and its integration (or my misuse) with it. The layout I received is intended to be used against several xml files I generate on my side. What I have to do is to take the layout and run the following process for every xml file I generated:

1. Import the xml file into the layout (I'd like to edit xml link indeed instead of an import xml command as the import does'nt give me the same results sometime)

2. Export as pdf

Loic.Aigon
Legend
October 8, 2009

Hi I was thinking to something like this :

//You need to download and place the xmljs library some place
//http://xmljs.sourceforge.net/index.html

//You need to adapt paths to your own system and folders

#include "/m/scripting/xml/xml_for_script-3.1/jsXMLParser/xmldom.js"

//Where your xml file is located
var myFile=File("/m/scripting/xml/test/datas.xml");
myFile.open('r');
var myXMLString = String(myFile.read());

//We make an XML object through xmljs library
var objDom = new XMLDoc(myXMLString, undefined) ;

var domTree = objDom.docNode;
var myImage = domTree.getElements("image");

//with false as a property, we ask Indesign to open the doc without showing us.
var doc= app.open(File('/m/scripting/xml/test/testXmlJs.indd'), false);

for(i=0; i<myImage.length; i++)
{
    //For each nodes "image" in the xml, we duplicate the page and change the content of the labeled frame
    var myPage = doc.pages[0].duplicate(LocationOptions.AT_END);
    var myFrame = myPage.pageItems.item("image");
    myFrame.place(File(myImage.getAttribute("href").replace('file:///','')));
   
    //we set options for the pdf export.
    app.pdfExportPreferences.pageRange = myPage.name;
    app.pdfExportPreferences.viewPDF=false; //set this to true if you want to open the PDF when created
    //PDF are created in this folder : "/m/scripting/xml/test/pdfXml"+i+".pdf"
    doc.exportFile(ExportFormat.pdfType, File("/m/scripting/xml/test/pdfXml"+(i+1)+".pdf"), undefined, undefined, undefined, undefined);
}

//We close the doc without saving
doc.close(SaveOptions.NO);

It's very basic and doesn't prevent misuse but functional if you respect the rules. Maybe it helps.

I join the indesign and xml I used with the script. And the generated PDF.