Skip to main content

Module sax

Module sax 

Source
Expand description

Streaming SAX-like API for HTML5 parsing.

Wraps the WHATWG HTML5 tokenizer to fire callbacks for each token without building a DOM tree in memory. This is useful for large HTML documents where you only need to extract specific data.

§Examples

use xmloxide::html5::sax::{Html5SaxHandler, parse_html5_sax};

struct Counter { elements: usize }

impl Html5SaxHandler for Counter {
    fn start_element(
        &mut self,
        name: &str,
        attributes: &[(String, String)],
        self_closing: bool,
    ) {
        self.elements += 1;
    }
}

let mut handler = Counter { elements: 0 };
parse_html5_sax("<div><p>Hello</p></div>", &mut handler);
assert_eq!(handler.elements, 2);

Structs§

DefaultHtml5Handler
A default no-op HTML5 SAX handler. Useful as a base or for testing.

Traits§

Html5SaxHandler
An event handler for streaming HTML5 parsing.

Functions§

parse_html5_sax
Parse HTML5 from a string, firing SAX events on the provided handler.