RegEx formatting replaced with XmlDocument to insert newline

RegEx solution was temporary and it was failing some edge cases. With `XmlDocument`, the formatting is now more robust.