Struct quick_xml::events::attributes::Attribute[][src]

pub struct Attribute<'a> {
    pub key: &'a [u8],
    pub value: Cow<'a, [u8]>,
}
Expand description

A struct representing a key/value XML attribute.

Field value stores raw bytes, possibly containing escape-sequences. Most users will likely want to access the value using one of the unescaped_value and unescape_and_decode_value functions.

Fields

key: &'a [u8]

The key to uniquely define the attribute.

If Attributes::with_checks is turned off, the key might not be unique.

value: Cow<'a, [u8]>

The raw value of the attribute.

Implementations

Returns the unescaped value.

This is normally the value you are interested in. Escape sequences such as &gt; are replaced with their unescaped equivalents such as >.

This will allocate if the value contains any escape sequences.

See also unescaped_value_with_custom_entities()

Returns the unescaped value, using custom entities.

This is normally the value you are interested in. Escape sequences such as &gt; are replaced with their unescaped equivalents such as >. Additional entities can be provided in custom_entities.

This will allocate if the value contains any escape sequences.

See also unescaped_value()

Pre-condition

The keys and values of custom_entities, if any, must be valid UTF-8.

Decode then unescapes the value

This allocates a String in all cases. For performance reasons it might be a better idea to instead use one of:

  • Reader::decode(), as it only allocates when the decoding can’t be performed otherwise.
  • unescaped_value(), as it doesn’t allocate when no escape sequences are used.

Decode then unescapes the value with custom entities

This allocates a String in all cases. For performance reasons it might be a better idea to instead use one of:

  • Reader::decode(), as it only allocates when the decoding can’t be performed otherwise.
  • [unescaped_value()], as it doesn’t allocate when no escape sequences are used.
Pre-condition

The keys and values of custom_entities, if any, must be valid UTF-8.

helper method to unescape then decode self using the reader encoding but without BOM (Byte order mark)

for performance reasons (could avoid allocating a String), it might be wiser to manually use

  1. BytesText::unescaped()
  2. Reader::decode(…)

helper method to unescape then decode self using the reader encoding with custom entities but without BOM (Byte order mark)

for performance reasons (could avoid allocating a String), it might be wiser to manually use

  1. BytesText::unescaped()
  2. Reader::decode(…)
Pre-condition

The keys and values of custom_entities, if any, must be valid UTF-8.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Creates new attribute from raw bytes. Does not apply any transformation to both key and value.

Examples
use quick_xml::events::attributes::Attribute;

let features = Attribute::from(("features".as_bytes(), "Bells &amp; whistles".as_bytes()));
assert_eq!(features.value, "Bells &amp; whistles".as_bytes());

Creates new attribute from text representation. Key is stored as-is, but the value will be escaped.

Examples
use quick_xml::events::attributes::Attribute;

let features = Attribute::from(("features", "Bells & whistles"));
assert_eq!(features.value, "Bells &amp; whistles".as_bytes());

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.