pub trait AttributeElementExt {
// Required method
fn try_attribute<F>(&self, attr_name: &str) -> Result<F, Error>
where F: FromStr,
F::Err: Error + Send + Sync + 'static;
// Provided method
fn attribute<F>(&self, attr_name: &str) -> Option<F>
where F: FromStr,
F::Err: Error + Send + Sync + 'static { ... }
}Expand description
Get an attribute from an element.
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl AttributeElementExt for Element
impl AttributeElementExt for Element
Source§fn try_attribute<F>(&self, attr_name: &str) -> Result<F, Error>
fn try_attribute<F>(&self, attr_name: &str) -> Result<F, Error>
Implementation of AttributeElementExt for Element gives you
access to the attribute’s value of an XML element. For example, the
id’s value of this XML element <tag id="value" />.
use minidom::Element;
use minidom_ext::AttributeElementExt;
let xml: &'static str = r#"<root id="42" />"#;
let root: Element = xml.parse().unwrap();
let id: u64 = root.try_attribute("id").unwrap();
assert_eq!(42, id);