Best way to approach JVM and JS DOMDocument manipulation

So, here is the situation.
Server: Kotin/JVM
Client: VanillaJS
DTO’s that are passed around: XML

This is error prone, because we have two locations where the DTO’s are made and this is difficult to maintain.

I am now investigating creating a separate Web Worker for the DTO generation (they can become quite complicated) and some heavy crunching of data.

Creating a DOMDocument is easy in JVM.
Creating a DOMDocument is easy in JS.

However, there are subtle changes and I need to use a common module for this to work on both platforms. And kotlin-common supports no DOMDocument.

I know there is the serialization library. However we have subtle, but documented, variations in our XML which show some fields or not, depending on some cases. Or they show some calculated fields. I don’t exactly know how to solve this with the serialization library.

One of the approaches would be to create a wrapper or interface and have the platforms implement that interface.

Another would be to use the expect and actual mechanism.

Are there any other options?

Do you know about

Yes I do actually. But I was under the impression that was for HTML. And since HTML is a specific markup language and XML a general one I thought it was not fully suitable actually. But I am going to investigate.

I don’t think it is what I need, unless I am completely not understanding it.

I need a common module where I generate XML which I can call client and server side. Looking at Kotlinx.HTML I only see that I can create it in JVM and JS, but not common.

OK, when I hear DOM, I usually understand HTML. It you want something to work with XML, the only thing I can recomment is a XML plugin for kotlinx-serialization. I use it myself and it allows to generate multiplatform bindings for XML entities, though not operate XML objects directly.

As for kotlinx-html, you can use it in common.