Fix validation for replacing a child node and refactor common logic into a block
Fix validation for replacing a child node and refactor common logic into a block

iabudiab/HTMLKit,iabudiab/HTMLKit,iabudiab/HTMLKit,iabudiab/HTMLKit,iabudiab/HTMLKit