quick_xml::reader

Struct Config

Source
#[non_exhaustive]
pub struct Config { pub allow_unmatched_ends: bool, pub check_comments: bool, pub check_end_names: bool, pub expand_empty_elements: bool, pub trim_markup_names_in_closing_tags: bool, pub trim_text_start: bool, pub trim_text_end: bool, }
Expand description

A struct that holds a parser configuration.

Current parser configuration can be retrieved by calling Reader::config() and changed by changing properties of the object returned by a call to Reader::config_mut().

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.
§allow_unmatched_ends: bool

Whether unmatched closing tag names should be allowed. Unless enabled, in case of a dangling end tag, the Error::IllFormed(UnmatchedEndTag) is returned from read methods.

When set to true, it won’t check if a closing tag has a corresponding opening tag at all. For example, <a></a></b> will be permitted.

Note that the emitted End event will not be modified if this is enabled, ie. it will contain the data of the unmatched end tag.

Note, that setting this to true will lead to additional allocates that needed to store tag name for an End event.

Default: false

§check_comments: bool

Whether comments should be validated. If enabled, in case of invalid comment Error::IllFormed(DoubleHyphenInComment) is returned from read methods.

When set to true, every Comment event will be checked for not containing --, which is not allowed in XML comments. Most of the time we don’t want comments at all so we don’t really care about comment correctness, thus the default value is false to improve performance.

Default: false

§check_end_names: bool

Whether mismatched closing tag names should be detected. If enabled, in case of mismatch the Error::IllFormed(MismatchedEndTag) is returned from read methods.

Note, that start and end tags should match literally, they cannot have different prefixes even if both prefixes resolve to the same namespace. The XML

<outer xmlns="namespace" xmlns:p="namespace">
</p:outer>

is not valid, even though semantically the start tag is the same as the end tag. The reason is that namespaces are an extension of the original XML specification (without namespaces) and it should be backward-compatible.

When set to false, it won’t check if a closing tag matches the corresponding opening tag. For example, <mytag></different_tag> will be permitted.

If the XML is known to be sane (already processed, etc.) this saves extra time.

Note that the emitted End event will not be modified if this is disabled, ie. it will contain the data of the mismatched end tag.

Note, that setting this to true will lead to additional allocates that needed to store tag name for an End event. However if expand_empty_elements is also set, only one additional allocation will be performed that support both these options.

Default: true

§expand_empty_elements: bool

Whether empty elements should be split into an Open and a Close event.

When set to true, all Empty events produced by a self-closing tag like <tag/> are expanded into a Start event followed by an End event. When set to false (the default), those tags are represented by an Empty event instead.

Note, that setting this to true will lead to additional allocates that needed to store tag name for an End event. However if check_end_names is also set, only one additional allocation will be performed that support both these options.

Default: false

§trim_markup_names_in_closing_tags: bool

Whether trailing whitespace after the markup name are trimmed in closing tags </a >.

If true the emitted End event is stripped of trailing whitespace after the markup name.

Note that if set to false and check_end_names is true the comparison of markup names is going to fail erroneously if a closing tag contains trailing whitespace.

Default: true

§trim_text_start: bool

Whether whitespace before character data should be removed.

When set to true, leading whitespace is trimmed in Text events. If after that the event is empty it will not be pushed.

Default: false

WARNING: With this option every text events will be trimmed which is incorrect behavior when text events delimited by comments, processing instructions or CDATA sections. To correctly trim data manually apply BytesText::inplace_trim_start and BytesText::inplace_trim_end only to necessary events.

§trim_text_end: bool

Whether whitespace after character data should be removed.

When set to true, trailing whitespace is trimmed in Text events. If after that the event is empty it will not be pushed.

Default: false

WARNING: With this option every text events will be trimmed which is incorrect behavior when text events delimited by comments, processing instructions or CDATA sections. To correctly trim data manually apply BytesText::inplace_trim_start and BytesText::inplace_trim_end only to necessary events.

Implementations§

Source§

impl Config

Source

pub fn trim_text(&mut self, trim: bool)

Set both trim_text_start and trim_text_end to the same value.

WARNING: With this option every text events will be trimmed which is incorrect behavior when text events delimited by comments, processing instructions or CDATA sections. To correctly trim data manually apply BytesText::inplace_trim_start and BytesText::inplace_trim_end only to necessary events.

Source

pub fn enable_all_checks(&mut self, enable: bool)

Turn on or off all checks for well-formedness. Currently it is that settings:

Trait Implementations§

Source§

impl<'arbitrary> Arbitrary<'arbitrary> for Config

Source§

fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

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 Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> 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 Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Config

Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,