Why can I not remove a child element I've just found? NOT_FOUND_ERR

后端 未结 4 1612
滥情空心
滥情空心 2021-01-07 20:20

I\'m building a script which has to patch XML files, including replacing one list of elements with another. The following function applies a patch (involving a possibly empt

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-07 20:29

    Building on the diagnosis by @Maurice and @fahd...

    Can't you just put a condition before

    parent.removeChild(node);
    

    such as

    if (parent.isSameNode(node.getParentNode()))
    

    Then it would only remove a direct child of the given parent.

提交回复
热议问题