pub struct Attribute<'a> {
pub key: QName<'a>,
pub value: Cow<'a, [u8]>,
}Expand description
A key/value XML attribute.
The value field stores raw bytes, possibly containing escape sequences. Most
users will want the value via normalized_value or
decoded_and_normalized_value.
Fields§
§key: QName<'a>The key that uniquely identifies 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 normalized_value(&self, version: XmlVersion) -> XmlResult<Cow<'a, str>>
pub fn normalized_value(&self, version: XmlVersion) -> XmlResult<Cow<'a, str>>
Returns the attribute value normalized as per the XML specification.
The document must be UTF-8 encoded. The characters \t, \r, \n are
replaced with a space (0x20), and the five predefined entities are
unescaped. This allocates unless no normalization is required.
Sourcepub fn normalized_value_with<'entity>(
&self,
version: XmlVersion,
depth: usize,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> XmlResult<Cow<'a, str>>
pub fn normalized_value_with<'entity>( &self, version: XmlVersion, depth: usize, resolve_entity: impl FnMut(&str) -> Option<&'entity str>, ) -> XmlResult<Cow<'a, str>>
Returns the attribute value normalized as per the XML specification, using a custom entity resolver. The document must be UTF-8 encoded.
§Parameters
depth: maximum number of nested entities that can be expanded beforeEscapeError::TooManyNestedEntitiesis returned;resolve_entity: resolves named entities (predefined entities are not resolved by this function, but you may callresolve_predefined_entity).
Sourcepub fn decoded_and_normalized_value(
&self,
version: XmlVersion,
decoder: Decoder,
) -> XmlResult<Cow<'a, str>>
pub fn decoded_and_normalized_value( &self, version: XmlVersion, decoder: Decoder, ) -> XmlResult<Cow<'a, str>>
Decodes using the provided decoder and returns the attribute value normalized as per the XML specification.
Sourcepub fn decoded_and_normalized_value_with<'entity>(
&self,
version: XmlVersion,
decoder: Decoder,
depth: usize,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> XmlResult<Cow<'a, str>>
pub fn decoded_and_normalized_value_with<'entity>( &self, version: XmlVersion, decoder: Decoder, depth: usize, resolve_entity: impl FnMut(&str) -> Option<&'entity str>, ) -> XmlResult<Cow<'a, str>>
Decodes using the provided decoder and returns the attribute value normalized as per the XML specification, using a custom entity resolver.
Sourcepub fn unescape_value(&self) -> XmlResult<Cow<'a, str>>
👎Deprecated: use Self::normalized_value()
Available on non-crate feature encoding only.
pub fn unescape_value(&self) -> XmlResult<Cow<'a, str>>
use Self::normalized_value()
encoding only.Returns the unescaped value.
Escape sequences such as > are replaced with their equivalents. This
allocates if the value contains any escape sequences.
Sourcepub fn unescape_value_with<'entity>(
&self,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> XmlResult<Cow<'a, str>>
👎Deprecated: use Self::normalized_value_with()
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>>
use Self::normalized_value_with()
encoding only.Decodes using UTF-8, then unescapes the value using a custom entity resolver.
Sourcepub fn decode_and_unescape_value(
&self,
decoder: Decoder,
) -> XmlResult<Cow<'a, str>>
👎Deprecated: use Self::decoded_and_normalized_value()
pub fn decode_and_unescape_value( &self, decoder: Decoder, ) -> XmlResult<Cow<'a, str>>
use Self::decoded_and_normalized_value()
Decodes, then unescapes the value.
Sourcepub fn decode_and_unescape_value_with<'entity>(
&self,
decoder: Decoder,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> XmlResult<Cow<'a, str>>
👎Deprecated: use Self::decoded_and_normalized_value_with()
pub fn decode_and_unescape_value_with<'entity>( &self, decoder: Decoder, resolve_entity: impl FnMut(&str) -> Option<&'entity str>, ) -> XmlResult<Cow<'a, str>>
use Self::decoded_and_normalized_value_with()
Decodes, then unescapes the value using a custom entity resolver.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
If the attribute value represents a valid boolean, returns Some,
otherwise None. The valid representations are "true", "false", "1"
and "0".
assert_eq!(Attribute::from(("attr", "false")).as_bool(), Some(false));
assert_eq!(Attribute::from(("attr", "1")).as_bool(), Some(true));
assert_eq!(Attribute::from(("attr", "not bool")).as_bool(), None);