[JS/CS6] How can I reach or remove text remains which is stuck in the XML Structure

Sometimes, the remnants of the deleted text are found at a parent level or root of the XML structure. How can I 'find' scripts?

Capture1.PNG

Above, a sample image. The root should be just '<>' and there may be hundreds of items marked under the root, which should not be deleted. The only thing that needs to be removed is the text that shows inside the element root, because it is not in use anywhere.

To fix it as I want, I can manually drag the document root, enter the editor mode (Ctrl + Y) and delete the text. I do in the editor mode to avoid the deletion of all the other child nodes of the root, which happens easily if I delete all the text in the textframe. When I delete the textframe, after you remove the top-level text which has been 'stuck' before, everything is nice.

I'd like one to write a script that deletes the text which has got stuck in the root of the way which is shown in the picture (the root is not in the page, it should be empty in case I'm on).

Defining the content of the xmlElement to "translates in all of the sub-elements being deleted (not what I want).

Thank you

Andreas

It of not elegant, but should work. I can't think of a way to distinguish the 0xFEFFs that "contain" children of other 0xFEFFs that you may have in the history of the root, so that would leave all the ones you hang out.

var root = app.activeDocument.xmlElements[0],
    i, character;

if (root.parentStory.constructor.name === 'XmlStory') {
    for (i = root.xmlContent.characters.length - 1; i >= 0; i--) {
        character = root.xmlContent.characters[i];
        if (character.contents.charCodeAt(0) !== 65279) {
            character.remove();
        }
    }
}

Jeff

Tags: InDesign

Similar Questions

Maybe you are looking for