Copy link to clipboard
Copied
I currently have a script that finds certain paragraph styles and renames them. For example:
var myDoc=app.activeDocument;
var myStyle=myDoc.paragraphStyles.itemByName("SIDEBAR B HEAD");
myStyle.name="SIDEBAR RATING HEAD"
I'd like to do the same thing with some XML tag names, preferably as part of the same script. I'm sure it's fairly easy, but for some reason I can't find any info on how to call out XML tags!
I've looked through the InDesign CS4 Scripting Tutorial and Adobe Introduction to Scripting, but at this point I feel like I'm wasting my time on a simple problem. Can anyone help out an amateur?
Thanks in advance,
Matt
Yes you are right Matt, its very easy.
var myDoc = app.activeDocument;
var myTag = myDoc.xmlTags.itemByName("Old");
myTag.name = "New";
Shonky
Copy link to clipboard
Copied
Yes you are right Matt, its very easy.
var myDoc = app.activeDocument;
var myTag = myDoc.xmlTags.itemByName("Old");
myTag.name = "New";
Shonky
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Or
You can use this function for multiple rename tag
var myDoc = app.activeDocument;
RenamXMLTag("Old", "New");
RenamXMLTag("Old", "New");
function RenamXMLTag(Old, New)
{
if(myDoc.xmlTags.itemByName(Old).isValid)
{
myDoc.xmlTags.itemByName(Old).name = New;
}
}
Shonky
Copy link to clipboard
Copied
Thanks! It looks like in that second version it also accomodates situations where the tag name doesn't exist—right? Is that what the "if" is for? Why is it "ReNam" and not "ReName"? Could you use this for paragraph styles too by changing "XMLTag" to "ParagraphStyle"? It seems there is always more than one way to do things in Javascript...
Thanks again. You have been so helpful today!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now