> For the complete documentation index, see [llms.txt](https://docs.yjs.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yjs.dev/api/shared-types/y.xmltext.md).

# Y.XmlText

```javascript
import * as Y from 'yjs'

const ydoc = new Y.Doc()

// You can define a Y.XmlText as a top-level type or a nested type

// Method 1: Define a top-level type
const yxmlText = ydoc.get('my xmltext type', Y.XmlText) 
// Method 2: Define Y.XmlText that can be included into the Yjs document
const yxmltextNested = new Y.XmlText()

// Nested types can be included as content into any other shared type
yxmlText.set('my nested text', ytextNested)

// Common methods (also available in Y.Text)
yxmlText.insert(0, 'abc') // insert three elements
yxmlText.format(1, 2, { bold: true }) // delete second element 
yxmlText.toDelta() // => [{ insert: 'a' }, { insert: 'bc', attributes: { bold: true }}]

// Methods specific to Y.XmlText
yxmlText.prevSibling
yxmlText.nextSibling
yxmlText.toString() // => "a<bold>bc</bold>"
```

## API

> Inherits from [Y.Text](/api/shared-types/y.text.md).

**`const yxmlText = Y.XmlText()`**

**`yxmlText.prevSibling: Y.XmlElement | Y.XmlText | null`**\
The previous sibling of this type. Is null if this is the first child of its parent.

**`yxmlText.nextSibling: Y.XmlElement | Y.XmlText | null`**\
The next sibling of this type. Is null if this is the last child of its parent.

**`yxmlText.toString(): string`**\
Returns the XML-String representation of this element. Formatting attributes are transformed to XML-tags. If the formatting attribute contains an object, the key-value pairs will be used as attributes. E.g.

```javascript
ymxlText.insert(0, "my link", { a: { href: 'https://..' } })
ymxlText.toString() // => <a href="https://..">my link</a>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.yjs.dev/api/shared-types/y.xmltext.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
