recurse xml remove all but first child
Hi,
I've tried searching for a solution and tried to adapt the code i found but I'm stuck.
I simply want to:
Delete all children bar the first child of all elements named "gr_name".
I've been looking at Remove xml element using JS[CS3] and got some inspiration.
I have the below code, which works if there is only two child elements.
If there is three or more I have to rerun the code which removes more elements.
I would very much appreciate if someone can help me locate the error or indicate what is missing.
var myDoc = app.activeDocument;
Table_Remove (myDoc);
function Table_Remove(elm)
{
for (var i = 0; i < elm.xmlElements.length; i++)
{
if(elm.xmlElements.markupTag.name == "gr_table")
{
for (var i2 =1; i2 < elm.xmlElements.xmlElements.length; i2++)
{
elm.xmlElements.xmlElements[i2].remove();
}
}
Table_Remove(elm.xmlElements);
}
}