OMElement existingDocumentElement = getOMDocumentElement();
if (existingDocumentElement == null) {
addChild(documentElement);
} else {
OMNode nextSibling = existingDocumentElement.getNextOMSibling();
existingDocumentElement.detach();
if (nextSibling == null) {
addChild(documentElement);
} else {
nextSibling.insertSiblingBefore(documentElement);
}