# Events

During the parsing, **LagartoParser** calls various callback methods of provided `TagVisitor` implementation.

### `start()` & `end()`

Invoked before and after the content is parsed.

### `text(CharSequence)`

Callback invoked on a block of plain text.

{% hint style="info" %}
Note that `text()` is called for **all** text blocks, including the whitespaces and indentations.&#x20;
{% endhint %}

### `comment(CharSequence)`

Invoked on an HTML comment. The argument contains the comment content, without the tag boundaries.

### `tag(Tag)`

Callback invoked foo all HTML tags: *open*, *close,* or an *empty* tag. The argument is a `Tag` instance, containing various information about the tag: tags name, attributes, depth level, etc.

{% hint style="warning" %}
`Tag` instance is **reused** during HTML parsing for better performances! The same `Tag`instance is passed to all callback methods and for every detected HTML tag. Do not store it internally!
{% endhint %}

### `script(Tag, CharSequence)`

Invoked on all `script` tags. The callback method receives the script Tag instance and the script body.

### `doctype(Doctype)`

Callback for the `doctype` tag.

### `xml()` and `cdata()`

These two callbacks are invoked for XML-specific tags when parsing the XML content.

### error(String)

Every error is reported by visiting this method. Depending on the configuration, the error message would contain the exact error position or not.


---

# Agent Instructions: 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:

```
GET https://lagarto.jodd.org/lagarto-parser/events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
