Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
alert(app.selection[0].associatedXMLElements[0].markupTag.name)
Shonky
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
ok Shonky,
If in the case while selection like i have to get like,
ce:label, ce:section-title like that.
Thanks
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
According to your code it gives only label and section.
But i need label and section-title.
Thanks
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now