Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Hi all,
I am modifying some code and it just isn't wanting to do what I am it to do 🙂 so probably user error!
The code is in jscript here is a small outline of the code:
doc = Application.activeDocument;
sel = doc.textSelection;
content = sel.extractContents();
// does some modifying of an attribute
// I would then like to add a processing instruction to the beginning and end of the selection.
// stick modified selection back in place
sel.insertNode(content);
My problem is that I have tried a few things to add the processing instruction and I can't get it to work. I found the method createProcessingInstruction( target, data) , but I think I am calling it wrong, or I don't have the correct insertBefore/After...
Any ideas?
Thanks,
Ellen
Here is more of the code:
// get a reference to the parent document
doc = Application.activeDocument;
sel = doc.textSelection;
// pull the selection out
content = sel.extractContents();
kids = content.childNodes;
// stick modified selection back in place
var piStart = Application.activeDocument.createProcessingInstruction('Start', 'type="+String+");
var piEnd = Application.activeDocument.createProcessingInstruction('End', 'type="+String+");
Application.activeDocument.insertBefore(piStart, kids.item(0));
Application.activeDocument.insertAfter(piEnd, kids.item(i-1));
sel.insertNode(content);
I got a little farther once I decided that the document fragment that I was extracting too was now the activeDocument. I least I think that is correct. The insertBefore seems to be giving me the error "DOM exception:node not found in current context."
I think I am having problems with my thinking about the "nodes" and "objects".
Thanks, Ellen
When I added:
var rootFragDoc = Application.activeDocument.documentElement;
rootFragDoc.insertBefore(piStart);
This put a PI in the large document not the extracted content, and at the end of the document right before the root end tag.
In Reply to Ellen Headrick:
Here is more of the code:
// get a reference to the parent document
doc = Application.activeDocument;
sel = doc.textSelection;// pull the selection out
content = sel.extractContents();kids = content.childNodes;
// stick modified selection back in place
var piStart = Application.activeDocument.createProcessingInstruction('Start', 'type="+String+");
var piEnd = Application.activeDocument.createProcessingInstruction('End', 'type="+String+");
Application.activeDocument.insertBefore(piStart, kids.item(0));
Application.activeDocument.insertAfter(piEnd, kids.item(i-1));
sel.insertNode(content);I got a little farther once I decided that the document fragment that I was extracting too was now the activeDocument. I least I think that is correct. The insertBefore seems to be giving me the error "DOM exception:node not found in current context."
I think I am having problems with my thinking about the "nodes" and "objects".
Thanks, Ellen
Clay,
THANK YOU, I owe you dinner when you come to Colorado!
Thanks,
Ellen