Skip to main content
Legend
December 28, 2013
Question

[JS] [CS6] How select text from XML structure

  • December 28, 2013
  • 1 reply
  • 1487 views

Hi,

I want with javascript select text from a XLM element (like screen capture : double-clic on "CHAINE", select "CINE CINEMA)

Thanks for your help

Regards

Ronald

This topic has been closed for replies.

1 reply

Kai Rübsamen
Participating Frequently
December 28, 2013

Hi Ronald,
I actually have no idea of ​​XML, but when I look at your screenshot, you can reach a specific element with the following lines. If you need all lines, you can loop through the elements.

// root-Element
var root = app.activeDocument.xmlElements[0];
// first child-Element
var notule = root.xmlElements[0];
// specific Element
var chaine = notule.xmlElements.itemByName("CHAINE");
alert (chaine.contents);

Kai

Ronald63Author
Legend
December 28, 2013

Hi Kai,

Thanks you for your answer, but I want selected on the page the XLMelement's contents, not get only ...

Regards

Kai Rübsamen
Participating Frequently
December 28, 2013

Ronald, did you try my lines? In most cases there is no need to select something. The line chaine.contents give you the content of the xml-element. chaine.characters or chaine.paragraphs gives you characters or  paragraphs. E.g. if you want to apply a character style to the content you could do something like:

var c = chaine.characters.everyItem();

c.appliedCharacterStyle = app.activeDocument.characterStyles.itemByName("red");