Updated serialization to properly serialize with xml format.

Thanks to Corey Oordt (@coordt) for initial patch.