XML icon indicating copy to clipboard operation
XML copied to clipboard

Allow to insert before/after a node to proceed with the reference node is undefined

Open ZzZombo opened this issue 7 years ago • 0 comments

Currently the library won't allow you to insert before/after if the reference node not found in the parent element's node list, including undefined ones. I want to insert a node after a node found by some criteria, like tag name, and if none found, insert before/after first/last child, and if there are no nodes at all, insert it as first child. First two can be easily done with one-liner like $parent.insertAfter($node,$parent.elements(:TAG<item>).tail // $parent.lastChild()), but to fulfill the last you have to check for child nodes and call a whole different method, like insert to actually insert a node, complicating the code quite a bit.

ZzZombo avatar Jan 29 '18 05:01 ZzZombo