What I'd ideally like to be able to refer to the rectangle by its XML tag - something like:
frame = doc.getRectangleByTag('Pic'); // <Pic> being the name of the XML tag
imgList = frame.place(new File(img));
Are you sure you want to do it this way?
Could you explain why? I suspect there is a better solution.
In any case, at least in my test case, the XML tag is associated with the image inside the frame and not the frame itself. So if you want the frame, you must get the image associated with the tag and then go up to the parent. This works in a simple test:
var frame = app.activeDocument.xmlElements. evaluateXPathExpression("//tennis"). graphics.parent; [object Rectangle]
This is great - thanks John - works as expected and enables me to replace
My justification for this is that I am working with a (complex) combination
of PHP Arrays, ExtendScript, XML and SOAP. If there's any other way you
recommend of doing it, I'm all ears.
I have never had a situation where I had to use InDesign XML. You can use script labels to identify specific objects -- preferrably custom script labels. You an also use object names in CS5 or later.
Going between generic XML and regular InDesign objects is pretty easy using E4X and ExtendScript.
Thanks Harbs, will bear this in mind.