---
title: "tinymce.html.SaxParser"
description: "This class parses HTML code using pure JavaScript and executes various events for each item it finds. It will always execute the events in the right order for tag soup code like &amp;lt;b&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;. It will also remove elements and attributes that doesn&amp;#x27;t fit the schema if the validate setting is enabled."
canonical_url: "https://www.tiny.cloud/docs/tinymce/5/apis/tinymce.html.saxparser/"
md_url: "https://www.tiny.cloud/docs/tinymce/5/apis/tinymce.html.saxparser/index.md"
version: "5"
last_updated: "2024-03-26T08:09:19Z"
tokens: 524
---
Important This page documents TinyMCE 5. For new projects, Tiny recommends using the latest, most up-to-date version. [See TinyMCE 8 documentation](../../../latest/).
# tinymce.html.SaxParser

This class parses HTML code using pure JavaScript and executes various events for each item it finds. It will always execute the events in the right order for tag soup code like <b><p></b></p>. It will also remove elements and attributes that doesn’t fit the schema if the validate setting is enabled.

## Examples

```javascript
var parser = new tinymce.html.SaxParser({
    validate: true,

    comment: function(text) {
        console.log('Comment:', text);
    },

    cdata: function(text) {
        console.log('CDATA:', text);
    },

    text: function(text, raw) {
        console.log('Text:', text, 'Raw:', raw);
    },

    start: function(name, attrs, empty) {
        console.log('Start:', name, attrs, empty);
    },

    end: function(name) {
        console.log('End:', name);
    },

    pi: function(name, text) {
        console.log('PI:', name, text);
    },

    doctype: function(text) {
        console.log('DocType:', text);
    }
}, schema);
```

## Summary

### Constructors

| Name | Summary | Defined by |
| --- | --- | --- |
| [SaxParser()](#SaxParser) | Constructs a new SaxParser instance. | `SaxParser` |

### Methods

| Name | Summary | Defined by |
| --- | --- | --- |
| [parse()](#parse) | Parses the specified HTML string and executes the callbacks for each item it finds. | `SaxParser` |

## Constructors

### SaxParser

```javascript
public constructor function SaxParser(settings: Object, schema: tinymce.html.Schema)
```
Constructs a new SaxParser instance.

#### Parameters

- `settings (Object)` - Name/value collection of settings. comment, cdata, text, start and end are callbacks.
- `schema (Schema)` - HTML Schema class to use when parsing.

## Methods

### parse()

```javascript
parse(html: String)
```
Parses the specified HTML string and executes the callbacks for each item it finds.

#### Examples

```javascript
SaxParser({...}).parse('<b>text</b>');
```

#### Parameters

- `html (String)` - Html string to sax parse.
