in reply to Formatting XML

Have you looked at XML::Tidy?