• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

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

Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

Hi,

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

Capture_d_eĢcran_28_12_13_14_54.jpg

Thanks for your help

Regards

Ronald

TOPICS
Scripting

Views

1.3K

Translate

Translate

Report

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
Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

Hi Kai,

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

Regards

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

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");

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

yes I tried your lines but I really need to select the text from xml elment šŸ˜‰

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

I'm interested in why you have to select the text?

In the meantime: I was not able to select the text, if I try chain.characters.everyItem().select().

But you can try:

chaine.texts.everyItem().select();

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

Thanks Kai, it works šŸ™‚

var root = app.activeDocument.xmlElements[0];

var notule = root.xmlElements[0];

var chaine = notule.xmlElements.itemByName("CHAINE");

chaine.texts.everyItem().select();

app.selection[0].fillColor= "DOC";

app.activeDocument.select(NothingEnum.NOTHING);

It's for TV Magazine, the script import on a page several "notule" and I must change the color of <CHAINE> depending on the notule's attribute "rubrique". There may be on the page, several identical <CHAINE> but with different colors.

Bonne soirƩe

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

In this case, I would loop through all 'chaines' and would apply the colors in dependence from the attribute or maybe do a GREP-Search.

However: I did not see the importance of selecting text. Instead of your last 3 lines, the following should also work:

chaine.texts.everyItem().fillColor = "DOC";

If you have more than one chain-element on the page, I would assume, that you get a error, if you try to select something?!

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

In my testfile this one assign a color in dependance of the value of the attribute:

// root-element

var root = app.activeDocument.xmlElements[0];

// loop through the children

for ( var i = 0; i < root.xmlElements.length; i++ ) {

  var notule = root.xmlElements;

  var rubNotule = notule.xmlAttributes.itemByName("rubrique");

  // specific Element

  var chaine = notule.xmlElements.itemByName("CHAINE");

  if ( rubNotule.value == "cinema" ) {

    chaine.texts.everyItem().fillColor = "DOC";

  }

  else if ( rubNotule.value == "TV" ) {

    chaine.texts.everyItem().fillColor = app.activeDocument.swatches[5];

  }

}

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 29, 2013 Dec 29, 2013

Copy link to clipboard

Copied

LATEST

You're right, why make it complicated when you can make simple šŸ˜‰

Thank you again for your help

Ronald

Votes

Translate

Translate

Report

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