Skip navigation
Currently Being Moderated

Javascript: Remove Unused Tag from Document based on name

Jun 28, 2012 7:21 AM

I am trying to remove an unused tag from the document based on name. 

 

I don't want to use app.activeDocument.deleteUnusedTags();

 

 

The code below removes the association between the item and the tag - but still leaves the tag in the tags panel:

 

var myDocument = app.activeDocument;

var xmlElements = myDocument.xmlElements;

 

for(var j=xmlElements.length-1; j>=0; j--){

 

       for(var k=xmlElements[j].xmlElements.length-1; k>=0; k--){

            var xmlTag = xmlElements[j].xmlElements.item(k).markupTag;

 

            if(xmlTag.name == "Tag1"){

                xmlElements[j].xmlElements[k].remove();

            }

       }

}

 

 

The code below deleted the tag and replaces it with Root - But I would like the pageitem to be untagged.

 

var myDocument = app.activeDocument;

var documentTags = myDocument.xmlTags;

for(var l=documentTags.length-1; l>=0; l--){

    if(documentTags[l].name == "Tag1"){

        var xmlTag = documentTags[l];

        xmlTag.remove("Root");

    }

}

 

Hopefully I am just missing something simple here...


Nathan Deamer

 

 

 

 

 


 
Replies
  • Currently Being Moderated
    Jun 29, 2012 9:39 PM   in reply to natdeamer

    1. You have to find the xml elements with "Tag1" applied.

    2. Then untag those xml elements

    3. And then delete the "Tag1" with "Root". (Note: All child elements associated with "Tag1" will also be deleted)

     

    -------------

    Green4ever

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points