It depends on whether you want to maintain formatting. You can use
myXMLElement.contents = app.selection.contents;
in the (unlikely?) event that you don't mind blowing away the formatting. Otherwise you'll want to use something like:
myXMLElement.xmlContent.remove(); app.selection.duplicate(LocationOptions.AT_BEGINNING, myXMLElement.xmlContent);
Thanx for your great help. It works like a charm. The world is a better place with people like you...
Just one additional question: I also tried using it for a selected picture, but this doesn't seem to work. Only for text.
Do you know if there is a solution for an image?
If you want to insert the rectangle inline, substitute
for the second line of the snippet I posted above.
I'm sorry for the confusion but what I meant was:
I would also like to be able to duplicate a selected Image into a tagged graphic frame (maybe replacing a existing image within the tagged graphic frame)
Any feedback would be awsome.
Maybe rather than thinking about how to replace the contents of the element you should just get rid of the old one and use the tag to mark up a duplicate of the selection.
var oldFrame = myXMLElement.xmlContent.parent instanceof Rectangle ? myXMLElement.xmlContent.parent : myXMLElement.xmlContent; var newFrame = app.selection.duplicate(); var coordinates = [oldFrame.visibleBounds, oldFrame.visibleBounds]; oldFrame.remove(); newFrame.markup(myXMLElement); newFrame.move(coordinates);
If the old image and the new one aren't the same dimensions you'll have to work that out somehow...