Move agent block to the top by manipulating XML

This fixes most cases of changing checksums, but not all of them
Make Resource Map XML reliably ordered by sorting elements