pub struct Attribute<'a, 'input: 'a> { /* private fields */ }
Expand description
An attribute.
Implementations§
source§impl<'a, 'input> Attribute<'a, 'input>
impl<'a, 'input> Attribute<'a, 'input>
sourcepub fn namespace(&self) -> Option<&'a str>
pub fn namespace(&self) -> Option<&'a str>
Returns attribute’s namespace URI.
§Examples
let doc = roxmltree::Document::parse(
"<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>"
).unwrap();
assert_eq!(doc.root_element().attributes().nth(0).unwrap().namespace(), None);
assert_eq!(doc.root_element().attributes().nth(1).unwrap().namespace(), Some("http://www.w3.org"));
sourcepub fn name(&self) -> &'input str
pub fn name(&self) -> &'input str
Returns attribute’s name.
§Examples
let doc = roxmltree::Document::parse(
"<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>"
).unwrap();
assert_eq!(doc.root_element().attributes().nth(0).unwrap().name(), "a");
assert_eq!(doc.root_element().attributes().nth(1).unwrap().name(), "a");
sourcepub fn value(&self) -> &'a str
pub fn value(&self) -> &'a str
Returns attribute’s value.
§Examples
let doc = roxmltree::Document::parse(
"<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>"
).unwrap();
assert_eq!(doc.root_element().attributes().nth(0).unwrap().value(), "b");
assert_eq!(doc.root_element().attributes().nth(1).unwrap().value(), "c");
sourcepub fn value_storage(&self) -> &StringStorage<'input>
pub fn value_storage(&self) -> &StringStorage<'input>
Returns attribute’s value storage.
Useful when you need a more low-level access to an allocated string.
sourcepub fn position(&self) -> usize
👎Deprecated: replaced by range
pub fn position(&self) -> usize
range
Returns attribute’s position in bytes in the original document.
You can calculate a human-readable text position via Document::text_pos_at.
<e attr='value'/>
^
sourcepub fn range(&self) -> Range<usize>
pub fn range(&self) -> Range<usize>
Returns attribute’s range in bytes in the original document.
<e n:attr='value'/>
^^^^^^^^^^^^^^
sourcepub fn range_qname(&self) -> Range<usize>
pub fn range_qname(&self) -> Range<usize>
Returns attribute’s qname’s range in bytes in the original document.
<e n:attr='value'/>
^^^^^^
To reduce memory usage the qname length is limited by u16::MAX. If the attribute exceeds that limit then the end of the returned range will be incorrect.
sourcepub fn range_value(&self) -> Range<usize>
pub fn range_value(&self) -> Range<usize>
Returns attribute’s value’s range in bytes in the original document, excluding the surrounding quotes.
If the attribute’s value is an empty string then the start
and end
of this Range
are equal, and indicate the closing quote.
<e n:attr='value'/>
^^^^^
To reduce memory usage the qname length is limited by u16::MAX, and the number of spaces around the equal sign is limited by u8::MAX. If the attribute exceeds those limits then the start of the returned range will be incorrect.