Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[CS3] [JS] add XML Element to Insertion Points

New Here ,
Jun 10, 2008 Jun 10, 2008
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();
}
}
TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 10, 2008 Jun 10, 2008
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 10, 2008 Jun 10, 2008
...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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2008 Jun 11, 2008
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2008 Jun 11, 2008
LATEST
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: fooi foo and the same behaviour as in the reply to dave encounters (return value = parent element)

do i use the contents attribute correct?

gregor
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines