Why does the ydoc.getXmlElement method not exist?

I see that all shared types have typed methods (getText, getMap,…) except XmlElement. Any particular reason?

Also, in the meantime, it is correct to do
const root = ydoc.get(userId, Y.XmlElement) as Y.XmlElement;?

Maybe you can use ydoc.getXmlFragment().

1 Like

Yes, I thought about it. I think I could do that.

However, I still wonder why XmlElement does not have a specific method and if there is something wrong with putting it as a top-level element.

Based on my architecture, I don’t see any impediment to it being an xmlFragment, but what happens if in the future I want to add, for example, an attribute, something that can only be done with xmlElement?

Good question, I’m not sure why there is no getXmlElement.

You might be able to achieve this by using an XmlFragment as the root, and then adding an XmlElement to it.

Also XmlElement extends XmlFragment. Not sure if that makes a difference.

It really is a good question. I just looked at code from dmonad himself and he used this function as well.

So maybe it did exist once?

Added ydoc.getXmlElement in v13.6.12.

1 Like

Awesome! Thanks @raine!

1 Like