Export an document as xml

I am trying to export document data as XML. However, when I serialize the fragment, it gets converted into HTML. I need it in XML format because my document contains unique codes and special characters that are being converted into their HTML entity representations. I want to preserve the unique codes exactly as they are.

How can I serialize the fragment as XML instead of HTML?

    const fragment = DOMSerializer.fromSchema(CustomSchema)?.serializeFragment(view.state.doc.content);
    const tempDiv = document.createElement('div');
    tempDiv.appendChild(fragment.cloneNode(true));

ProseMirror’s DOMSerializer does not do any entity conversion. It outputs a DOM structure. How you serialize that to a string is up to you.