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

renaming XML tags via Javascript

Contributor ,
Sep 03, 2010 Sep 03, 2010

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

TOPICS
Scripting
1.9K
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

Engaged , Sep 03, 2010 Sep 03, 2010

Yes you are right Matt, its very easy.

var myDoc = app.activeDocument;
var myTag = myDoc.xmlTags.itemByName("Old");
myTag.name = "New";

Shonky

Translate
Engaged ,
Sep 03, 2010 Sep 03, 2010

Yes you are right Matt, its very easy.

var myDoc = app.activeDocument;
var myTag = myDoc.xmlTags.itemByName("Old");
myTag.name = "New";

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
Engaged ,
Sep 03, 2010 Sep 03, 2010

Hey,

Use Jongware InDesign OM and you can easily search any code.

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
Engaged ,
Sep 03, 2010 Sep 03, 2010

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

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
Contributor ,
Sep 03, 2010 Sep 03, 2010
LATEST

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!

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