DomParser

Trait DomParser 

Source
pub trait DomParser<'de> {
    type Error: Error + 'static;

    // Required methods
    fn next_event(&mut self) -> Result<Option<DomEvent<'de>>, Self::Error>;
    fn peek_event(&mut self) -> Result<Option<&DomEvent<'de>>, Self::Error>;
    fn skip_node(&mut self) -> Result<(), Self::Error>;

    // Provided methods
    fn current_span(&self) -> Option<Span> { ... }
    fn is_lenient(&self) -> bool { ... }
    fn format_namespace(&self) -> Option<&'static str> { ... }
    fn capture_raw_node(&mut self) -> Result<Option<Cow<'de, str>>, Self::Error> { ... }
}
Expand description

A parser that emits DOM events from a tree-structured document.

Implementations exist for HTML (using html5gum) and XML parsers.

Required Associated Types§

Source

type Error: Error + 'static

The error type for parsing failures.

Required Methods§

Source

fn next_event(&mut self) -> Result<Option<DomEvent<'de>>, Self::Error>

Get the next event from the document.

Returns Ok(None) when the document is fully parsed.

Source

fn peek_event(&mut self) -> Result<Option<&DomEvent<'de>>, Self::Error>

Peek at the next event without consuming it.

Source

fn skip_node(&mut self) -> Result<(), Self::Error>

Skip the current node and all its descendants.

This is used when encountering unknown elements that should be ignored. After calling this, the parser should be positioned after the matching NodeEnd.

Provided Methods§

Source

fn current_span(&self) -> Option<Span>

Get the current span in the source document, if available.

Source

fn is_lenient(&self) -> bool

Whether this parser is lenient about text in unexpected places.

HTML parsers return true - text without a corresponding field is silently discarded. XML parsers return false - text without a corresponding field is an error.

Source

fn format_namespace(&self) -> Option<&'static str>

Returns the format namespace for this parser (e.g., “xml”, “html”).

This is used to select format-specific proxy types when a field has #[facet(xml::proxy = XmlProxy)] or similar format-namespaced proxies.

Returns None by default, which falls back to format-agnostic proxies.

Source

fn capture_raw_node(&mut self) -> Result<Option<Cow<'de, str>>, Self::Error>

Capture the current node as raw markup and skip past it.

Must be called right after receiving a NodeStart event. Returns the raw source text for the entire element (from opening tag through closing tag).

Returns None if raw capture is not supported by this parser.

Implementors§