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

Select xml element in structure pane by javascript

Engaged ,
Dec 25, 2016 Dec 25, 2016

Dear All,

Is it possible to select multiple xml elements with their names in structure pane with js?

Below is my attachment:

structure pane.PNG

I have a script that select only one element, _p or _img. I need to select all tags except "Article" tags.

var doc = app.activeDocument;

var rt = doc.xmlElements[0];

var _p = rt.xmlElements.item("_p");

var _img = rt.xmlElements.item("_img");

_p.select();

_img.select();

Thanks,

Sumit

-Sumit
TOPICS
Scripting
3.5K
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

correct answers 1 Correct answer

People's Champ , Dec 26, 2016 Dec 26, 2016

var doc = app.activeDocument; 

var rt = doc.xmlElements[0];

var allButArticle = rt.evaluateXPathExpression (".//*[name()!='Article']" );

if ( allButArticle.length ) app.select ( allButArticle );

Translate
People's Champ ,
Dec 26, 2016 Dec 26, 2016

var doc = app.activeDocument; 

var rt = doc.xmlElements[0];

var allButArticle = rt.evaluateXPathExpression (".//*[name()!='Article']" );

if ( allButArticle.length ) app.select ( allButArticle );

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
Engaged ,
Dec 26, 2016 Dec 26, 2016

Thank you so much Loic!

-Sumit
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
Engaged ,
Dec 26, 2016 Dec 26, 2016

Dear Loic,

There is one issue, when I run this command next then select also every Item of under Article Tag.

Below is my scenario.

Screen Shot 2016-12-26 at 3.21.44 PM.png

I do not need to select any element under Article also.

My complete script is here:

app.scriptMenuActions.itemByID(78815).invoke(); 

var doc = app.activeDocument;

var rt = doc.xmlElements[0];

var allButArticle = rt.evaluateXPathExpression (".//*[name()!='Article']" );

if ( allButArticle.length ) app.select ( allButArticle );

try{ 

app.scriptMenuActions.itemByID(78818).invoke(); 

}catch(e){$.writeln(e.message)};

//}

Regards,

Sumit

-Sumit
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
People's Champ ,
Dec 30, 2016 Dec 30, 2016

app.scriptMenuActions.itemByID(78815).invoke();   

 

var doc = app.activeDocument;  

var rt = doc.xmlElements[0]; 

var allButArticle = rt.evaluateXPathExpression ("./*[name()!='Article']" ); 

if ( allButArticle.length ) app.select ( allButArticle ); 

 

try{   

app.scriptMenuActions.itemByID(78818).invoke();   

}catch(e){$.writeln(e.message)};

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
Engaged ,
Dec 30, 2016 Dec 30, 2016

Thank you Loic,

Yes your code working great!

Regards,

Sumit

-Sumit
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
Community Beginner ,
Apr 14, 2020 Apr 14, 2020
LATEST

Hello, this question is really late, but do you know how I may select a XML tag in the story.

I need to import an XML file with specific tags on words, and to be able to generate shape around those words, I need to get their bounds.

I cannot find any example, and the lack of documentation conducted me here.

Thanks in advance.
Loïc (me too)

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