valid XML: add an XML declaration to all XML output.

Also do basic escaping for variable values.