---
title: "tinymce.dom.Serializer"
description: "This class is used to serialize DOM trees into a string. Consult the TinyMCE API Documentation for more details and examples on how to use this class."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.dom.serializer/"
md_url: "https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.dom.serializer/index.md"
version: "6"
last_updated: "2022-07-13T05:38:26Z"
tokens: 1354
---
Important This page documents TinyMCE 6. For new projects, Tiny recommends using the latest, most up-to-date version. [See TinyMCE 8 documentation](../../../latest/apis/tinymce.dom.serializer/).
# tinymce.dom.Serializer

This class is used to serialize DOM trees into a string. Consult the TinyMCE API Documentation for more details and examples on how to use this class.

## Summary

### Methods

| Name | Summary | Defined by |
| --- | --- | --- |
| [addAttributeFilter()](#addAttributeFilter) | Adds an attribute filter function to the parser used by the serializer, the parser will collect nodes that has the specified attributes and then execute the callback once it has finished parsing the document. | `Serializer` |
| [addNodeFilter()](#addNodeFilter) | Adds a node filter function to the parser used by the serializer, the parser will collect the specified nodes by name and then execute the callback once it has finished parsing the document. | `Serializer` |
| [addRules()](#addRules) | Adds valid elements rules to the serializers schema instance this enables you to specify things like what elements should be outputted and what attributes specific elements might have. Consult the TinyMCE Documentation for more details on this format. | `Serializer` |
| [addTempAttr()](#addTempAttr) | Adds a temporary internal attribute these attributes will get removed on undo and when getting contents out of the editor. | `Serializer` |
| [getTempAttrs()](#getTempAttrs) | Returns an array of all added temp attrs names. | `Serializer` |
| [removeAttributeFilter()](#removeAttributeFilter) | Removes an attribute filter function or removes all filter functions from the parser used by the serializer for the attribute names provided. | `Serializer` |
| [removeNodeFilter()](#removeNodeFilter) | Removes a node filter function or removes all filter functions from the parser used by the serializer for the node names provided. | `Serializer` |
| [serialize()](#serialize) | Serializes the specified browser DOM node into a HTML string. | `Serializer` |
| [setRules()](#setRules) | Sets the valid elements rules to the serializers schema instance this enables you to specify things like what elements should be outputted and what attributes specific elements might have. Consult the TinyMCE Documentation for more details on this format. | `Serializer` |

## Methods

### addAttributeFilter()

```javascript
addAttributeFilter(name: String, callback: Function)
```
Adds an attribute filter function to the parser used by the serializer, the parser will
collect nodes that has the specified attributes
and then execute the callback once it has finished parsing the document.

#### Examples

```javascript
serializer.addAttributeFilter('src,href', (nodes, name) => {
  for (let i = 0; i < nodes.length; i++) {
    console.log(nodes[i].name);
  }
});
```

#### Parameters

- `name (String)` - Comma separated list of attributes to collect.
- `callback (Function)` - Callback function to execute once it has collected nodes.

### addNodeFilter()

```javascript
addNodeFilter(name: String, callback: Function)
```
Adds a node filter function to the parser used by the serializer, the parser will collect the specified nodes by name
and then execute the callback once it has finished parsing the document.

#### Examples

```javascript
serializer.addNodeFilter('p,h1', (nodes, name) => {
  for (let i = 0; i < nodes.length; i++) {
    console.log(nodes[i].name);
  }
});
```

#### Parameters

- `name (String)` - Comma separated list of nodes to collect.
- `callback (Function)` - Callback function to execute once it has collected nodes.

### addRules()

```javascript
addRules(rules: String)
```
Adds valid elements rules to the serializers schema instance this enables you to specify things
like what elements should be outputted and what attributes specific elements might have.
Consult the TinyMCE Documentation for more details on this format.

#### Parameters

- `rules (String)` - Valid elements rules string to add to schema.

### addTempAttr()

```javascript
addTempAttr(name: String)
```
Adds a temporary internal attribute these attributes will get removed on undo and
when getting contents out of the editor.

#### Parameters

- `name (String)` - string

### getTempAttrs()

```javascript
getTempAttrs(): String[]
```
Returns an array of all added temp attrs names.

#### Return value

- `String[]` - Array with attribute names.

### removeAttributeFilter()

```javascript
removeAttributeFilter(name: String, callback: Function)
```
Removes an attribute filter function or removes all filter functions from the parser used by the serializer for the attribute names provided.

#### Examples

```javascript
// Remove a single filter
serializer.removeAttributeFilter('src,href', someCallback);

// Remove all filters
serializer.removeAttributeFilter('src,href');
```

#### Parameters

- `name (String)` - Comma separated list of attribute names to remove filters for.
- `callback (Function)` - Optional callback function to only remove a specific callback.

### removeNodeFilter()

```javascript
removeNodeFilter(name: String, callback: Function)
```
Removes a node filter function or removes all filter functions from the parser used by the serializer for the node names provided.

#### Examples

```javascript
// Remove a single filter
serializer.removeNodeFilter('p,h1', someCallback);

// Remove all filters
serializer.removeNodeFilter('p,h1');
```

#### Parameters

- `name (String)` - Comma separated list of node names to remove filters for.
- `callback (Function)` - Optional callback function to only remove a specific callback.

### serialize()

```javascript
serialize(node: DOMNode, args: Object)
```
Serializes the specified browser DOM node into a HTML string.

#### Parameters

- `node (DOMNode)` - DOM node to serialize.
- `args (Object)` - Arguments option that gets passed to event handlers.

### setRules()

```javascript
setRules(rules: String)
```
Sets the valid elements rules to the serializers schema instance this enables you to specify things
like what elements should be outputted and what attributes specific elements might have.
Consult the TinyMCE Documentation for more details on this format.

#### Parameters

- `rules (String)` - Valid elements rules string.
