Struct data::xml::Parser

source ·
pub struct Parser<'a> { /* private fields */ }
Expand description

A simple event callback-based XML parser.

Implementations§

source§

impl<'a> Parser<'a>

source

pub fn new() -> Self

Create a parser with no callbacks.

source

pub fn addBeginHandler<F>(&mut self, tag: &'static str, handler: F)where F: FnMut(&[String], &BytesStart<'_>) -> Result<(), Error> + 'a,

Add a callback for an opening tag. If the parser encounters an opening tag whose name coincides with the value of tag, it calls handler with the opening tag event. Self-closing tags also trigger begin handlers.

source

pub fn addEndHandler<F>(&mut self, tag: &'static str, handler: F)where F: FnMut(&[String], &BytesEnd<'_>) -> Result<(), Error> + 'a,

Add a callback for an end tag. If the parser encounters an end tag whose name coincides with the value of tag (not including the starting /), it calls handler with the end tag event. Self-closing tags also trigger end handlers.

source

pub fn addTextHandler<F>(&mut self, tag: &'static str, handler: F)where F: FnMut(&[String], &str) -> Result<(), Error> + 'a,

Add a callback for text element directly inside some tag. If the parser encounters a text element where it’s enclosing tag coincides with the value of tag, it calls handler with the decoded text string.

Note that this does not mean the text needs to be the only or the last element in the enclosing tag.

source

pub fn addTagHandler<F>(&mut self, tag: &'static str, handler: F)where F: FnMut(&[String], &[u8]) -> Result<(), Error> + 'a,

Add a callback for a whole tag. If the parser encounters an opening element (including self-closing tags) whose name coincides with the value of tag, it calls handler with the content of the whole tag, including the opening and the closing tag. The parser then skips the whole tag.

This is useful if the user wants to delegate the parsing of a tag to another parser.

source

pub fn parse(&mut self, x: &[u8]) -> Result<(), Error>

Parse the XML in the byte buffer x, triggering the callbacks in the process. It is important to note that this buffer should only contains one root tag.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Parser<'a>

§

impl<'a> !Send for Parser<'a>

§

impl<'a> !Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> !UnwindSafe for Parser<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.