Struct quick_xml::events::attributes::Attribute
source · pub struct Attribute<'a> {
pub key: QName<'a>,
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 unescape_value
and decode_and_unescape_value
functions.
Fields§
§key: QName<'a>
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§
source§impl<'a> Attribute<'a>
impl<'a> Attribute<'a>
sourcepub fn unescape_value(&self) -> XmlResult<Cow<'a, str>>
Available on non-crate feature encoding
only.
pub fn unescape_value(&self) -> XmlResult<Cow<'a, str>>
encoding
only.Decodes using UTF-8 then unescapes the 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.
See also unescape_value_with()
This method is available only if encoding
feature is not enabled.
sourcepub fn unescape_value_with<'entity>(
&self,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> XmlResult<Cow<'a, str>>
Available on non-crate feature encoding
only.
pub fn unescape_value_with<'entity>( &self, resolve_entity: impl FnMut(&str) -> Option<&'entity str>, ) -> XmlResult<Cow<'a, str>>
encoding
only.Decodes using UTF-8 then unescapes the 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 >
.
A fallback resolver for additional custom entities can be provided via
resolve_entity
.
This will allocate if the value contains any escape sequences.
See also unescape_value()
This method is available only if encoding
feature is not enabled.
sourcepub fn decode_and_unescape_value(
&self,
decoder: Decoder,
) -> XmlResult<Cow<'a, str>>
pub fn decode_and_unescape_value( &self, decoder: Decoder, ) -> XmlResult<Cow<'a, str>>
Decodes then unescapes the value.
This will allocate if the value contains any escape sequences or in non-UTF-8 encoding.
sourcepub fn decode_and_unescape_value_with<'entity>(
&self,
decoder: Decoder,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> XmlResult<Cow<'a, str>>
pub fn decode_and_unescape_value_with<'entity>( &self, decoder: Decoder, resolve_entity: impl FnMut(&str) -> Option<&'entity str>, ) -> XmlResult<Cow<'a, str>>
Decodes then unescapes the value with custom entities.
This will allocate if the value contains any escape sequences or in non-UTF-8 encoding.
Trait Implementations§
source§impl<'a> From<(&'a [u8], &'a [u8])> for Attribute<'a>
impl<'a> From<(&'a [u8], &'a [u8])> for Attribute<'a>
source§fn 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());
source§impl<'a> From<(&'a str, &'a str)> for Attribute<'a>
impl<'a> From<(&'a str, &'a str)> for Attribute<'a>
source§fn 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());
impl<'a> Eq for Attribute<'a>
impl<'a> StructuralPartialEq for Attribute<'a>
Auto Trait Implementations§
impl<'a> Freeze for Attribute<'a>
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)