xml::reader

Struct ParserConfig2

Source
#[non_exhaustive]
pub struct ParserConfig2 { pub override_encoding: Option<Encoding>, pub ignore_invalid_encoding_declarations: bool, pub allow_multiple_root_elements: bool, pub max_entity_expansion_length: usize, pub max_entity_expansion_depth: u8, pub max_name_length: usize, pub max_attributes: usize, pub max_attribute_length: usize, pub max_data_length: usize, /* private fields */ }
Expand description

Backwards-compatible extension of ParserConfig, which will eventually be merged into the original ParserConfig struct

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§override_encoding: Option<Encoding>

Use this encoding as the default. Necessary for UTF-16 files without BOM.

§ignore_invalid_encoding_declarations: bool

Allow <?xml encoding="…"> to contain unsupported encoding names, and interpret them as Latin1 instead. This will mangle non-ASCII characters, but usually it won’t fail parsing.

§allow_multiple_root_elements: bool

Documents with multiple root elements are ill-formed

§max_entity_expansion_length: usize

Abort if custom entities create a string longer than this

§max_entity_expansion_depth: u8

Entities can expand into other entities this many times (be careful about exponential cost!)

§max_name_length: usize

Maximum length of tag name or attribute name

§max_attributes: usize

Max number of attributes per element

§max_attribute_length: usize

Max number of bytes in each attribute

§max_data_length: usize

Maximum length of strings reprsenting characters, comments, and processing instructions

Implementations§

Source§

impl ParserConfig2

Source

pub fn new() -> Self

Create extended configuration struct

Source

pub fn content_type(self, mime_type: &str) -> Self

Read character encoding from Content-Type header. Set this when parsing XML documents fetched over HTTP.

text/* MIME types do not imply latin1. UTF-8 is always the default fallback.

Source

pub fn create_reader<R: Read>(self, source: R) -> EventReader<R>

Creates an XML reader with this configuration.

This is a convenience method for configuring and creating a reader at the same time:

use xml::reader::ParserConfig;

let mut source: &[u8] = b"...";

let reader = ParserConfig::new()
    .trim_whitespace(true)
    .ignore_comments(true)
    .coalesce_characters(false)
    .create_reader(&mut source);

This method is exactly equivalent to calling EventReader::new_with_config() with this configuration object.

Source§

impl ParserConfig2

Source

pub const fn override_encoding(self, value: Option<Encoding>) -> Self

Set if you got one in the HTTP header

See ParserConfig fields docs for details

Source

pub const fn allow_multiple_root_elements(self, value: bool) -> Self

Allows invalid documents. There should be only a single root element in XML.

See ParserConfig fields docs for details

Source

pub const fn max_entity_expansion_length(self, value: usize) -> Self

Abort if custom entities create a string longer than this

See ParserConfig fields docs for details

Source

pub const fn max_entity_expansion_depth(self, value: u8) -> Self

Entities can expand into other entities this many times (be careful about exponential cost!)

See ParserConfig fields docs for details

Source

pub const fn max_attributes(self, value: usize) -> Self

Max number of attributes per element

See ParserConfig fields docs for details

Source

pub const fn max_name_length(self, value: usize) -> Self

Maximum length of tag name or attribute name

See ParserConfig fields docs for details

Source

pub const fn max_attribute_length(self, value: usize) -> Self

Max number of bytes in each attribute

See ParserConfig fields docs for details

Source

pub const fn max_data_length(self, value: usize) -> Self

Maximum length of strings reprsenting characters, comments, and processing instructions

See ParserConfig fields docs for details

Source

pub const fn ignore_invalid_encoding_declarations(self, value: bool) -> Self

Allow <?xml encoding="bogus"?>

See ParserConfig fields docs for details

Source§

impl ParserConfig2

Source

pub const fn trim_whitespace(self, value: bool) -> Self

See ParserConfig fields docs for details

Source

pub const fn whitespace_to_characters(self, value: bool) -> Self

See ParserConfig fields docs for details

Source

pub const fn cdata_to_characters(self, value: bool) -> Self

See ParserConfig fields docs for details

Source

pub const fn ignore_comments(self, value: bool) -> Self

See ParserConfig fields docs for details

Source

pub const fn coalesce_characters(self, value: bool) -> Self

See ParserConfig fields docs for details

Source

pub const fn ignore_end_of_stream(self, value: bool) -> Self

See ParserConfig fields docs for details

Source

pub const fn replace_unknown_entity_references(self, value: bool) -> Self

See ParserConfig fields docs for details

Source

pub const fn ignore_root_level_whitespace(self, value: bool) -> Self

Whether or not whitespace at the root level of the document is ignored. Default is true.

See ParserConfig fields docs for details

Trait Implementations§

Source§

impl Clone for ParserConfig2

Source§

fn clone(&self) -> ParserConfig2

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParserConfig2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ParserConfig2

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<ParserConfig> for ParserConfig2

Source§

fn from(c: ParserConfig) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ParserConfig2

Source§

fn eq(&self, other: &ParserConfig2) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ParserConfig2

Source§

impl StructuralPartialEq for ParserConfig2

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.