diff -rupN --no-dereference libxml2-v2.9.12/xmlsave.c libxml2-v2.9.12-new/xmlsave.c --- libxml2-v2.9.12/xmlsave.c 2022-02-18 21:00:14.226540564 +0100 +++ libxml2-v2.9.12-new/xmlsave.c 2022-02-18 21:00:14.229540592 +0100 @@ -890,6 +890,13 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr break; case XML_ELEMENT_NODE: + if ((cur != root) && (ctxt->format == 1) && + (xmlIndentTreeOutput)) + xmlOutputBufferWrite(buf, ctxt->indent_size * + (ctxt->level > ctxt->indent_nr ? + ctxt->indent_nr : ctxt->level), + ctxt->indent); + /* * Some users like lxml are known to pass nodes with a corrupted * tree structure. Fall back to a recursive call to handle this @@ -900,13 +907,6 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr break; } - if ((ctxt->level > 0) && (ctxt->format == 1) && - (xmlIndentTreeOutput)) - xmlOutputBufferWrite(buf, ctxt->indent_size * - (ctxt->level > ctxt->indent_nr ? - ctxt->indent_nr : ctxt->level), - ctxt->indent); - xmlOutputBufferWrite(buf, 1, "<"); if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix);