fixed replace_with() and parent()

to avoid calling appendChild() on a Document node, which is not supported by XML::LibXML.