Replaced manual XML outout with the TinyXML library routines. Not yet validated