Are you sure that's even possible in Indesign? I would think this is perfectly logical.
Perhaps you could move all children one level up the XML chain before removing its parent.
(For any next questions, you might want to add just a little more information. This forum is not manned by response robots.)
Are you sure that's even possible in Indesign?
In UI when you untag parent - all childrens remain tagged and are moved to parent's level.
(Just had to see that for myself)
You are correct, Robin. Only when using 'delete' in the Structure pane everything inside gets untagged as well.
Verifying the JS help shows there are two ways: XMLElement.remove and untag. Unfortunately, their descriptions merely state "deletes an XMLElement" and "untags an XMLElement" -- no more help there!
So either it doesn't work like that from a script (always a possibility), or the OP used 'remove' where he should have used 'untag'.