function to serialize XML documents