Delete a set of tags - Indesign
Hi everybody.
I need some help with the code below. Unfortunately, I have no experience with the Java language, but I guess that (for my needs) it should be easy to get to a solution.
The code below helps me to automate a compilation of an instruction manual automatically deleting tags (in Indesign).
In particular, I create a “database document” with all the parts of the manual, each tagged with a particular XML tag.
Now, the process that I want to automate is:
- Declare a set of tags to be deleted (in the code below “tag01”, “tag02”, and “tag03”);
- Delete the contents marked with the above tags;
- Delete empty frames.
I found the code below that should do these operations, but it deletes only a part (I don’t know why!) of the contents marked with tag to be deleted. Anyone can help me?
Further, does anybody know a code that allows me to declare a set of tags in an external file, as an example a txt file or js file, and then take these tags in the script in object (operation n°1)?
P.S. The operation n°3 work correctly.
In this figure is shown a part of the xml schema of the document in object.
Thank you for your time.
var myDocument= app.activeDocument;
// 1. Declare a set of tags to be deleted
var tag_da_eliminare = new Array();
tag_da_eliminare[0] = "tag01";
tag_da_eliminare[1] = "tag02";
tag_da_eliminare[2] = "tag03";
// 2. Delete the contents marked with the above tags
for (var j=0; j<tag_da_eliminare.length; j++) {
var tag_incriminato = tag_da_eliminare
alert(tag_incriminato)
FindEmail(myDocument);
}
// 3. Delete empty frames (WORK CORRECTLY)
var myStories = app.activeDocument.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
var myTextFrames = myStories.textContainers;
for (j = myTextFrames.length - 1; j >= 0; j--) {
if (myTextFrames
myTextFrames
}
}
}
alert("process Completed");
// FUNCTIONS
function FindEmail(elm)
{
for (var i=0; i<elm.xmlElements.length; i++)
{
XMLelementName=elm.xmlElements.markupTag.name.toString();
if(XMLelementName==tag_incriminato)
{
//elm.xmlElements.markupTag = "mail";
elm.xmlElements.remove();
//alert(i);
}
FindEmail(elm.xmlElements);
}
}
