1 Reply Latest reply on May 8, 2013 6:35 AM by SimonLinden

    Delete and replace XML-tag

    SimonLinden

      How do I delete an XML tag and replace it using script? There's a function for adding tags to the document (activeDocument.xmlTags.add("xml-tag")), but I can't find a corresponding function to delete it, and replace with another as you would in the GUI.

       

      I tried to accomplish this by changing the name of the tag to one I wanted using the code below, but it throws the error: "A tag with that name already exists.  Please choose a different name."

       

      for(var i=0;i<xmlTags.length;i++){
           xmlTags[i].markupTag.name = "existing-xml-tag";
      }
      

      Does anyone know of a way to go around this error or should I use another method entirely?

        • 1. Re: Delete and replace XML-tag
          SimonLinden Level 1

          Ok, this wasn't so difficult to solve. I was looking at the wrong place that's all. The remove(replaceWith) function is available from the XMLTag class. Meaning the followin code removes the tag called "p-new-section" and replaces it with the existing tag called "p".

           

          myDoc.xmlTags.itemByName("p-new-section").remove("p");