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

Tags within a text selection...

New Here ,
Feb 22, 2010 Feb 22, 2010

Hi everybody,


Is there a way to know if a text selection contains any xml tag?


I get a text object from a selection:

var myDocument = app.activeDocument;
var mySelection = myDocument.selection;
var myText = mySelection[0];

The only thing I can do is "myText.associatedXMLElements" to get the XML element in the XML structure... It gives first xml element.

but I need to know which tags I have within my selection.



Would be great a suggestion.

Thanks.

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
Engaged ,
Feb 22, 2010 Feb 22, 2010

alert(app.selection[0].associatedXMLElements[0].markupTag.name)

Shonky

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 ,
Feb 22, 2010 Feb 22, 2010

hi Shonky,

It shows only first element name,like "label"

eg)

<tag><label>My label<caption>my Caption</caption></label></tag>

I need to display label, caption....

If there is any possible way.

Thanks.

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 ,
Feb 22, 2010 Feb 22, 2010

insert your cursor in my Caption text and run below code:

alert(app.selection[0].associatedXMLElements[0].parent.markupTag.name +", " + app.selection[0].associatedXMLElements[0].markupTag.name)

Shonky

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 ,
Feb 22, 2010 Feb 22, 2010

ok Shonky,

If in the case while selection like i have to get like,

sel.JPG

ce:label, ce:section-title like that.

Thanks

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 ,
Feb 22, 2010 Feb 22, 2010

I think it works for you,

alert(app.selection[0].associatedXMLElements[0].parent.xmlElements[0].markupTag.name+", " + app.selection[0].associatedXMLElements[0].markupTag.name)

Shonky

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 ,
Feb 22, 2010 Feb 22, 2010

According to your code it gives only label and section.

But i need label and section-title.

Thanks

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 ,
Feb 22, 2010 Feb 22, 2010

Is it your reslut?

alert(app.selection[0].associatedXMLElements[0].parent.xmlElements[0].markupTag.name+", " + app.selection[0].associatedXMLElements[0].parent.xmlElements[1].markupTag.name)

Shonky

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 ,
Feb 22, 2010 Feb 22, 2010

No Shonky, be clear when i am selected the text i have know how many element are taged in the selection.

for example see the picture... otherwise i need the count of element taged..

Thanks

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 ,
Feb 22, 2010 Feb 22, 2010
LATEST

dear, hope it will help you, but your cursor must placed inside the "ce:section-title" tag.

paragraph_index = app.selection[0].parentStory.insertionPoints.itemByRange (0, app.selection[0].index).paragraphs.length;

alert (app.selection[0].parentStory.paragraphs[paragraph_index-2].characters[1].associatedXMLElements[0].markupTag.name +", " + app.selection[0].parentStory.paragraphs[paragraph_index-1].characters[1].associatedXMLElements[0].markupTag.name)

Shonky

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