# perldoc > XML::LibXML::SAX

---
type: CommandReference
command: XML::LibXML::SAX
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `XML::LibXML::SAX->new(Handler => $handler)` — create a new SAX parser with a handler
- `$parser->parse_file($filename)` — parse an XML file, generating SAX events
- `$parser->parse_chunk($data)` — parse well-balanced XML chunks, generating SAX events
- `$parser->set_feature('http://xmlns.perl.org/sax/join-character-data', 1)` — enable character data joining for speed boost

## Name

`XML::LibXML::SAX` — direct SAX parser for `XML::LibXML`

## Synopsis

perl
use XML::LibXML::SAX;
my $handler = MyHandler->new();
my $parser = XML::LibXML::SAX->new(Handler => $handler);
$parser->parse_file('large.xml');
# or for chunked data:
$parser->parse_chunk($chunk);
$parser->set_feature('http://xmlns.perl.org/sax/join-character-data', 1);
## Description

`XML::LibXML::SAX` provides a direct SAX interface to libxml2. It generates SAX events during parsing without creating a DOM tree. This is useful for processing very large XML documents efficiently, reading data directly into application structures.

It is based on the generic `XML::SAX` interface and `XML::SAX::Base`. Additionally, it provides `parse_chunk()` for generating SAX events from well-balanced data (e.g., from databases).

## Options

- `set_feature('http://xmlns.perl.org/sax/join-character-data', $flag)` — enable (1) or disable (0) character data joining. May yield significant speed boost in low-markup-ratio situations. Default is disabled. **Note:** Experimental.

## Examples

perl
use XML::LibXML::SAX;
my $handler = MyHandler->new();
my $parser = XML::LibXML::SAX->new(Handler => $handler);
# Parse a file
$parser->parse_file('data.xml');
# Parse a chunk of balanced XML
$parser->parse_chunk('<record>...</record>');
## See Also

- [XML::LibXML](https://metacpan.org/pod/XML::LibXML)
- [XML::SAX](https://metacpan.org/pod/XML::SAX)
- [XML::SAX::Base](https://metacpan.org/pod/XML::SAX::Base)