0
[CS3] [JS] add XML Element to Insertion Points
New Here
,
/t5/indesign-discussions/cs3-js-add-xml-element-to-insertion-points/td-p/1159064
Jun 10, 2008
Jun 10, 2008
Copy link to clipboard
Copied
hi list,
i'll do some text parsing in indesign cs3 intended to add some xml elements to my document.
i just wonder why i can't markup an insertion point. is the following approach correct? The code works fine, only the return value (stored in the _xml variable) is not the new element but the parent element. The same code works without using the insertion point (marking up the text object [xmlElements.add(_dokument.xmlTags.item("index") , erg[0]))] ).
Any ideas or thoughts?
var _dokument = app.activeDocument;
main ();
// ** main ()
function main() {
//Set the find options.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences= NothingEnum.nothing;
//find any string encloased by @
app.findGrepPreferences.findWhat = "@.*?@";
erg = _dokument.findGrep();
while (erg.length > 0) {
_xml = _dokument.xmlElements[0].xmlElements.item("text").xmlElements.add(_dokument.xmlTags.item("index") , erg[0].insertionPoints[0]);
erg[0].contents = "";
erg = _dokument.findGrep();
}
}
i'll do some text parsing in indesign cs3 intended to add some xml elements to my document.
i just wonder why i can't markup an insertion point. is the following approach correct? The code works fine, only the return value (stored in the _xml variable) is not the new element but the parent element. The same code works without using the insertion point (marking up the text object [xmlElements.add(_dokument.xmlTags.item("index") , erg[0]))] ).
Any ideas or thoughts?
var _dokument = app.activeDocument;
main ();
// ** main ()
function main() {
//Set the find options.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences= NothingEnum.nothing;
//find any string encloased by @
app.findGrepPreferences.findWhat = "@.*?@";
erg = _dokument.findGrep();
while (erg.length > 0) {
_xml = _dokument.xmlElements[0].xmlElements.item("text").xmlElements.add(_dokument.xmlTags.item("index") , erg[0].insertionPoints[0]);
erg[0].contents = "";
erg = _dokument.findGrep();
}
}
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/indesign-discussions/cs3-js-add-xml-element-to-insertion-points/m-p/1159065#M338416
Jun 10, 2008
Jun 10, 2008
Copy link to clipboard
Copied
If you try it in the UI, you'll see that when only an insertion point is selected and you try to tag it, the whole story is tagged.
I don't think that what you're trying can be done. You have to tag content, not the lack of it. However, what you could do is insert some temporary text at the insertion point, tag that and then delete the text. That will have the effect you're trying to achieve.
Dave
I don't think that what you're trying can be done. You have to tag content, not the lack of it. However, what you could do is insert some temporary text at the insertion point, tag that and then delete the text. That will have the effect you're trying to achieve.
Dave
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explorer
,
/t5/indesign-discussions/cs3-js-add-xml-element-to-insertion-points/m-p/1159066#M338417
Jun 10, 2008
Jun 10, 2008
Copy link to clipboard
Copied
...but you can enter a character in the contents of the insertion point, tag it, and then delete the character. This creates an empty element at the insertion point. Not elegant, but it works.:-)
Thanks,
Ole
Thanks,
Ole
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_hp__
AUTHOR
New Here
,
/t5/indesign-discussions/cs3-js-add-xml-element-to-insertion-points/m-p/1159067#M338418
Jun 11, 2008
Jun 11, 2008
Copy link to clipboard
Copied
hi dave,
gui testing is always a good idea 🙂 but in this case the behaviour is different:
your observation is correct (anyway at least a strange behaviour compared to any xml editing tool i know == how adobe intended to insert an empty element?), tagging in the gui a tagged insertion point tags the whole story.
in the script a new element is added but the return value is the parent element (the xmlElement of the whole story).
this causes a problem when i add an attribute (the intention of the above script is to add references) which is added to the parent element.
gregor
gui testing is always a good idea 🙂 but in this case the behaviour is different:
your observation is correct (anyway at least a strange behaviour compared to any xml editing tool i know == how adobe intended to insert an empty element?), tagging in the gui a tagged insertion point tags the whole story.
in the script a new element is added but the return value is the parent element (the xmlElement of the whole story).
this causes a problem when i add an attribute (the intention of the above script is to add references) which is added to the parent element.
gregor
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_hp__
AUTHOR
New Here
,
LATEST
/t5/indesign-discussions/cs3-js-add-xml-element-to-insertion-points/m-p/1159068#M338419
Jun 11, 2008
Jun 11, 2008
Copy link to clipboard
Copied
hi olav,
maybe i'm not firm with insertion points, but your solution does not work:
_insert = erg[0].insertionPoints[0];
_insert.contents = "i";
_xml = dokument.xmlElements[0].xmlElements.item("text").xmlElements.add(_dokument.xmlTags.item("index") , _insert );
leads to the following xml structure: foo i foo and the same behaviour as in the reply to dave encounters (return value = parent element)
do i use the contents attribute correct?
gregor
maybe i'm not firm with insertion points, but your solution does not work:
_insert = erg[0].insertionPoints[0];
_insert.contents = "i";
_xml = dokument.xmlElements[0].xmlElements.item("text").xmlElements.add(_dokument.xmlTags.item("index") , _insert );
leads to the following xml structure: foo
do i use the contents attribute correct?
gregor
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

