Y.XmlElement
A shared type that represents an XML node
import * as Y from 'yjs'
const ydoc = new Y.Doc()
// You can define a Y.XmlElement as a top-level type or a nested type
// Method 1: Define a top-level type
// Note that the nodeName is always "undefined"
// when defining an XmlElement as a top-level type.
const yxmlElement = ydoc.get('prop-name', Y.XmlElement)
// Method 2: Define Y.XmlFragment that can be included into the Yjs document
const yxmlNested = new Y.XmlElement('node-name')
// Common methods
const yxmlText = new Y.XmlText()
yxmlFragment.insert(0, [yxmlText])
yxmlFragment.firstChild === yxmlText
yxmlFragment.insertAfter(yxmlText, [new Y.XmlElement('node-name')])
yxmlFragment.get(0) === yxmlText // => true
//show result in dev console
console.log(yxmlFragment.toDOM())API
Observing changes: Y.XmlEvent
Y.XmlEvent API
Last updated
