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
sourceimpl<'a> Attribute<'a>
impl<'a> Attribute<'a>
sourcepub fn unescaped_value(&self) -> XmlResult<Cow<'_, [u8]>>
pub fn unescaped_value(&self) -> XmlResult<Cow<'_, [u8]>>
Returns the unescaped value.
This is normally the value you are interested in. Escape sequences such as >
are
replaced with their unescaped equivalents such as >
.
This will allocate if the value contains any escape sequences.
sourcepub fn unescaped_value_with_custom_entities(
&self,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>
) -> XmlResult<Cow<'_, [u8]>>
pub fn unescaped_value_with_custom_entities(
&self,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>
) -> XmlResult<Cow<'_, [u8]>>
Returns the unescaped value, using custom entities.
This is normally the value you are interested in. Escape sequences such as >
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.
sourcepub fn unescape_and_decode_value<B: BufRead>(
&self,
reader: &Reader<B>
) -> XmlResult<String>
pub fn unescape_and_decode_value<B: BufRead>(
&self,
reader: &Reader<B>
) -> XmlResult<String>
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.
sourcepub fn unescape_and_decode_value_with_custom_entities<B: BufRead>(
&self,
reader: &Reader<B>,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>
) -> XmlResult<String>
pub fn unescape_and_decode_value_with_custom_entities<B: BufRead>(
&self,
reader: &Reader<B>,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>
) -> XmlResult<String>
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_with_custom_entities()
, 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.
sourcepub fn unescape_and_decode_without_bom<B: BufRead>(
&self,
reader: &Reader<B>
) -> XmlResult<String>
pub fn unescape_and_decode_without_bom<B: BufRead>(
&self,
reader: &Reader<B>
) -> XmlResult<String>
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
- BytesText::unescaped()
- Reader::decode(…)
sourcepub fn unescape_and_decode_without_bom_with_custom_entities<B: BufRead>(
&self,
reader: &Reader<B>,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>
) -> XmlResult<String>
pub fn unescape_and_decode_without_bom_with_custom_entities<B: BufRead>(
&self,
reader: &Reader<B>,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>
) -> XmlResult<String>
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
- BytesText::unescaped()
- Reader::decode(…)
Pre-condition
The keys and values of custom_entities
, if any, must be valid UTF-8.
Trait Implementations
sourceimpl<'a> From<(&'a [u8], &'a [u8])> for Attribute<'a>
impl<'a> From<(&'a [u8], &'a [u8])> for Attribute<'a>
sourcefn from(val: (&'a [u8], &'a [u8])) -> Attribute<'a>
fn from(val: (&'a [u8], &'a [u8])) -> Attribute<'a>
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 & whistles".as_bytes()));
assert_eq!(features.value, "Bells & whistles".as_bytes());
sourceimpl<'a> From<(&'a str, &'a str)> for Attribute<'a>
impl<'a> From<(&'a str, &'a str)> for Attribute<'a>
sourcefn from(val: (&'a str, &'a str)) -> Attribute<'a>
fn from(val: (&'a str, &'a str)) -> Attribute<'a>
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 & whistles".as_bytes());
sourceimpl<'a> PartialEq<Attribute<'a>> for Attribute<'a>
impl<'a> PartialEq<Attribute<'a>> for Attribute<'a>
impl<'a> StructuralPartialEq for Attribute<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Attribute<'a>
impl<'a> Send for Attribute<'a>
impl<'a> Sync for Attribute<'a>
impl<'a> Unpin for Attribute<'a>
impl<'a> UnwindSafe for Attribute<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more