I need to replace specific elements within my XML structure with an image and I'm having problems using the existing XML structure for this.
I was hoping for something as simple as myDoc.xmlElements.xmlElements.xmlElements.contents = new File("MyImgPath.ext");
I can use GREP to find the text of each item in my XML structure I wish to replace, remove the text and place the image and the result is what I want. However, in the rare situation where the same text as the header, is in one of the paragraphs it too would be replaced with the image and we can't have that.
My XML structure is slightly more complicated but this example has the necessary elements:
Well I managed to find a solution to my problem. I'm not sure if it's the best way to go about it but it works for me.
var myDoc = app.open('//the/path/to/my/doc', OpenOptions.OPEN_COPY);
var myXML = myDoc.xmlElements.xmlElements[x].xmlElements;
var myImg = new FIle('//path/to/my/image');
myXML.contents = ''; // To clear out all the text
myDoc.select( myXML ); // Selects the xmlElement
myDoc.selection.insertionPoints.place( myImg ); // Places the image in the selection