pub struct Element {
pub name: Name,
pub attrs: Vec<Attribute>,
pub children: Vec<Node>,
pub self_closing: bool,
}Expand description
An element: its name, its attributes in the order they were written, and its children.
Fields§
§name: NameThe element’s name.
attrs: Vec<Attribute>Attributes in document order, including any namespace declarations.
children: Vec<Node>Children in document order.
self_closing: boolTrue when the element was written <a/>. Only consulted when there are
no children, and exists so that a round trip does not rewrite every
empty element in the document.
Implementations§
Source§impl Element
impl Element
Sourcepub fn new(prefix: &str, local: &str, ns: Ns) -> Self
pub fn new(prefix: &str, local: &str, ns: Ns) -> Self
A new element with no attributes and no children.
Sourcepub fn attr(&self, ns: &Ns, local: &str) -> Option<&str>
pub fn attr(&self, ns: &Ns, local: &str) -> Option<&str>
The value of an attribute, by namespace and local name.
Sourcepub fn attr_usize(&self, ns: &Ns, local: &str) -> Option<usize>
pub fn attr_usize(&self, ns: &Ns, local: &str) -> Option<usize>
The value of an attribute, read as an integer. Absent, or present and
unreadable, are the same answer: ODF’s own default applies either way and
a document that says table:number-columns-repeated="many" is not a
reason to refuse the document.
Sourcepub fn elements_indexed(&self) -> impl Iterator<Item = (usize, &Element)>
pub fn elements_indexed(&self) -> impl Iterator<Item = (usize, &Element)>
Every child element with its index among the children, which is the step a path through the tree takes to reach it.
Sourcepub fn at(&self, path: &[usize]) -> Option<&Element>
pub fn at(&self, path: &[usize]) -> Option<&Element>
The element a path of child indices leads to, counting every node and not only the elements. An empty path is this element.
Sourcepub fn child_mut(&mut self, ns: &Ns, local: &str) -> Option<&mut Element>
pub fn child_mut(&mut self, ns: &Ns, local: &str) -> Option<&mut Element>
The first child element with the given name, for changing it.
Sourcepub fn at_mut(&mut self, path: &[usize]) -> Option<&mut Element>
pub fn at_mut(&mut self, path: &[usize]) -> Option<&mut Element>
The same, for changing what is there.
Sourcepub fn set_attr(&mut self, name: Name, value: impl Into<String>)
pub fn set_attr(&mut self, name: Name, value: impl Into<String>)
Set an attribute: the value replaced where the attribute is there, the attribute appended where it is not.
Sourcepub fn remove_attr(&mut self, ns: &Ns, local: &str) -> Option<String>
pub fn remove_attr(&mut self, ns: &Ns, local: &str) -> Option<String>
Remove an attribute, answering the value it had.
Sourcepub fn name_for(&self, ns: &Ns, local: &str) -> Name
pub fn name_for(&self, ns: &Ns, local: &str) -> Name
A name for writing under this element, in the prefix it declares for the namespace, or the conventional one where it declares none.
Sourcepub fn child(&self, ns: &Ns, local: &str) -> Option<&Element>
pub fn child(&self, ns: &Ns, local: &str) -> Option<&Element>
The first child element with the given name.
Sourcepub fn descendant(&self, ns: &Ns, local: &str) -> Option<&Element>
pub fn descendant(&self, ns: &Ns, local: &str) -> Option<&Element>
The first descendant element with the given name, depth first.
Sourcepub fn plain_text(&self) -> String
pub fn plain_text(&self) -> String
Every character of text under this element, with ODF’s own whitespace elements turned back into the characters they stand for.
text:s is a run of spaces, text:tab a tab and text:line-break a
newline, because ODF collapses literal runs of whitespace and spells out
what it means instead. This is what a spreadsheet cell’s displayed string
and a search over a document both read.
Trait Implementations§
impl Eq for Element
impl StructuralPartialEq for Element
Auto Trait Implementations§
impl Freeze for Element
impl RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl UnsafeUnpin for Element
impl UnwindSafe for Element
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.