Save UML class diagram in UML file format

I have a requirement to save UML class diagram in UML file format. Please let me know if there is a way to achieve this functionality.

I followed below sample to implement UML class diagram

Sorry, rendering in some particular XML file format is not part of that sample – you’ll need to implement that yourself.