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

Add XML Element "img" to all elements as attribute

Contributor ,
Dec 30, 2015 Dec 30, 2015

Copy link to clipboard

Copied

Hi friends,

I want to add an attribute to an all element tag "img", but I don't see how to do it programmatically. Is it possible? Also, is there a way to name an element tag dynamically? For example: screenshot


my added attribute for (data-profile-deliveryformat=“digital”)


Screen Shot 2015-12-31 at 12.01.49 PM.png


Advance thanks,

TOPICS
Scripting

Views

343

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 30, 2015 Dec 30, 2015

Copy link to clipboard

Copied

Try this,

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

var imgTag = root.evaluateXPathExpression('//img');

for(var i=0; i<imgTag.length; i++)

{

    imgTag.xmlAttributes.add("data-profile-deliveryformat", "digital");

}

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
Contributor ,
Dec 31, 2015 Dec 31, 2015

Copy link to clipboard

Copied

Hi Sajeev,

First fall Thanks your quick replay,

I have run in the your code but some error is happen. plz find out this problem. what can i do sajeev.

Indesign Cs6

Screen Shot 2015-12-31 at 1.28.09 PM.png

Advance thanks

Karthik S

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 31, 2015 Dec 31, 2015

Copy link to clipboard

Copied

Use the below line at the top of your script

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

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
Contributor ,
Dec 31, 2015 Dec 31, 2015

Copy link to clipboard

Copied

Hi Sajeev,


I have used your code below:

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

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

var imgTag = root.evaluateXPathExpression('//img'); 

for(var i=0; i<imgTag.length; i++) 

    imgTag.xmlAttributes.add("data-profile-deliveryformat", "digital"); 

}

But this is not add the xml attributes ("data-profile-deliveryformat", "digital") sajeev, plz tell again what can i do?

Thanks

Karthik

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
Contributor ,
Dec 31, 2015 Dec 31, 2015

Copy link to clipboard

Copied

LATEST

Hi Sajeev,


I and using application = cs6



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