pub struct HtmlSaxParser<H>where
H: HtmlSaxHandler + 'static,{ /* private fields */ }Expand description
Push-based HTML parser. Caller drives input chunks via feed;
the parser dispatches events synchronously into the registered
handler as they’re produced.
libxml2 htmlCreatePushParserCtxt + htmlParseChunk analogue,
or lxml’s HTMLParser(target=…) + parser.feed(bytes).
§Example
use sup_xml_core::html::{HtmlAttrs, HtmlSaxHandler, HtmlSaxParser};
#[derive(Default)]
struct LinkCollector {
hrefs: Vec<String>,
}
impl HtmlSaxHandler for LinkCollector {
fn start_element(&mut self, name: &str, attrs: HtmlAttrs<'_>) {
if name == "a" {
if let Some(href) = attrs.get("href") {
self.hrefs.push(href.to_string());
}
}
}
}
let html = r#"<a href="/x">x</a><a href="/y">y</a>"#;
let mut p = HtmlSaxParser::new(LinkCollector::default());
p.feed(html).unwrap();
let collector = p.finish().unwrap();
assert_eq!(collector.hrefs, vec!["/x", "/y"]);Implementations§
Source§impl<H> HtmlSaxParser<H>where
H: HtmlSaxHandler + 'static,
impl<H> HtmlSaxParser<H>where
H: HtmlSaxHandler + 'static,
Sourcepub fn new(handler: H) -> HtmlSaxParser<H>
pub fn new(handler: H) -> HtmlSaxParser<H>
Create a push parser with default options.
Sourcepub fn with_opts(handler: H, opts: HtmlParseOptions) -> HtmlSaxParser<H>
pub fn with_opts(handler: H, opts: HtmlParseOptions) -> HtmlSaxParser<H>
Create a push parser with explicit options.
Auto Trait Implementations§
impl<H> !Freeze for HtmlSaxParser<H>
impl<H> !RefUnwindSafe for HtmlSaxParser<H>
impl<H> !Send for HtmlSaxParser<H>
impl<H> !Sync for HtmlSaxParser<H>
impl<H> Unpin for HtmlSaxParser<H>where
H: Unpin,
impl<H> UnsafeUnpin for HtmlSaxParser<H>where
H: UnsafeUnpin,
impl<H> UnwindSafe for HtmlSaxParser<H>where
H: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more