Two DOM structures for a single logical document structure

Our ProseMirror application has two schemas, one for dealing with our XML save format, and one for dealing with the HTML DOM. Both have the same node structure, with the idea being that the schemas allow us to serialize the same document multiple ways. We’ve made this work, though now I realize that perhaps we’re not doing things the right way, and I could use some guidance.

In order to load our XML into a PM document (which ultimately refers to the HTML schema), I’m using the DOMParser.schemaRules function like this:

const parser = DOMParser(editorSchema, DOMParser.schemaRules(xmlSchema)

That is, I want a document which internally refers to the editorSchema, but I want to use the xmlSchema rules to do the parsing of XML. And this seems to work just fine.

Unfortunately, I see that DOMParser.schemaRules is marked @internal, so I presumably shouldn’t be using it. This leads me to to my main question: how can I use ProseMirror schemas to to support two different DOM formats for a single notional document structure? Documents seem to keep references to their schema (via references in their nodes), and interoperability between documents with different schemas seems to be prohibited, even when the document structures are identical.

I’ve seen some discussions that might be relevant (e.g. Translating nodes and transaction steps between editors with different schemas), but I’m not sure how to apply to advice I see there.

So, is it possible to do what I’m trying to do? If so, what’s the trick? If not, what’s the done thing for supporting multiple DOM formats for a document? I feel like this is supported and that I’ve just missed the trick for doing so.

DOMParser.fromSchema(schema).rules is the exported equivalent of DOMParser.schemaRule(schema).

1 Like

Ah, that’s excellent, thanks!