Small fixes to XML and generate SQL