[−][src]Struct exile::Element
Represents an Element in an XML Document.
Implementations
impl Element
[src]
pub fn from_name<S: Into<String>>(name: S) -> Self
[src]
Create a new element using the given name.
pub fn children(&self) -> impl Iterator<Item = &Element>
[src]
Returns the 'child' elements of the current element. Consider the XML document:
<r>
<a/>
<b/>
</r>
r's children()
function would return an iterator over 'a' and 'b'.
Text nodes, processing instructions and comments are skipped/ignored by the iterator.
pub fn child<S: AsRef<str>>(&self, name: S) -> Option<&Element>
[src]
Find the first occurrance specific child element (does not recurse to lower levels of children).
pub fn add_child(&mut self, element: Element)
[src]
Add an element as a child of this element.
pub fn add_cdata<S: Into<String>>(&mut self, cdata: S) -> Result<(), XDocErr>
[src]
Add a CDATA
node. Will error if the string contains ]]>
as this cannot be represented in
a CDATA
node.
pub fn nodes_len(&self) -> usize
[src]
Get the number of nodes (of any kind) that are children of this node.
pub fn first_node(&self) -> Option<&Node>
[src]
Get the first child node (of any kind)
pub fn node(&self, index: usize) -> Option<&Node>
[src]
Get the child node (of any kind) at index
.
pub fn fullname(&self) -> &str
[src]
The fullname of the element (including both the namespace alias prefix and the name). For
example, if the name of this element is ns:foo
, this function returns "ns:foo"
.
Element::name
and [Element:prefix
] give the parsed sections of the fullname.
pub fn name(&self) -> &str
[src]
The name of the element without its prefix. For example, if the name of this element is
ns:foo
, name()
will return foo
.
pub fn prefix(&self) -> Option<&str>
[src]
The name of the element's namespace alias prefix. For example, if the name of this element
is ns:foo
, prefix()
will return Some("ns")
.
pub fn set_name<S: AsRef<str>>(&mut self, name: S)
[src]
Sets the name of this element without changing the namespace alias prefix. For example, if
the name of this element is ns:foo
then set_name("bar")
will change the fullname to
ns:bar
.
pub fn set_prefix<S: AsRef<str>>(&mut self, prefix: S) -> Result<(), XDocErr>
[src]
Sets the namespace alias prefix of this element without changing the name. For example, if
the name of this element is ns:foo
then set_prefix("xyz:) will change the fullname to
xyz:foo`.
pub fn set_fullname<S: Into<String>>(
&mut self,
fullname: S
) -> Result<(), XDocErr>
[src]
&mut self,
fullname: S
) -> Result<(), XDocErr>
Sets the fullname of the element. For example, if the name of this element is ns:foo
, then
set_fullname("xyz:baz")
will set the fullname to xyz:baz
. set_fullname("baz")
will
eliminate any existing namespace alias prefix and set the fullname to baz
.
pub fn add_attribute<K, V>(&mut self, key: K, value: V) -> Option<String> where
K: AsRef<str>,
V: AsRef<str>,
[src]
K: AsRef<str>,
V: AsRef<str>,
Inserts a key-value pair into the attributes map.
If the map did not have this key present, None
is returned.
If the map did have this key present, the value is updated, and the old value is returned.
pub fn attribute<S: AsRef<str>>(&self, key: S) -> Option<&String>
[src]
Gets the attribute value at key
. None
if an attribute by that name does not exist.
pub fn attributes_len(&self) -> usize
[src]
Gets the count of attributes.
pub fn attributes(&self) -> impl Iterator<Item = (&String, &String)> + '_
[src]
Gets an iterator over the attribute key/value pairs.
pub fn attribute_keys(&self) -> impl Iterator<Item = &String> + '_
[src]
Gets an iterator over the attribute keys
pub fn add_new_child(&mut self) -> Result<&mut Element, XDocErr>
[src]
Creates a new element as the last child of this element and returns a mut ref to it.
pub fn add_text<S: AsRef<str>>(&mut self, text: S)
[src]
Append a text node to this element's nodes.
pub fn add_pi(&mut self, pi: PI)
[src]
Append a processing instruction to this element's nodes.
pub fn add_comment<S: Into<String>>(
&mut self,
comment: S
) -> Result<(), XDocErr>
[src]
&mut self,
comment: S
) -> Result<(), XDocErr>
Append a processing instruction to this element's nodes.
pub fn has_children(&self) -> bool
[src]
Does this element have any sub elements. For example, if the element is empty or contains only text and/or pis and/or comments, then false. if the element has elements, then true.
pub fn is_text(&self) -> bool
[src]
Returns true if there is exactly one sub node, and that sub node is either text or cdata.
pub fn text(&self) -> Option<String>
[src]
Returns the contents of the first Text
or CData
node encountered in the element. Useful
for simple 'text' elements like <something>text is here</something>
where this function
will return Some("text is here")
.
pub fn write<W>(
&self,
writer: &mut W,
opts: &WriteOpts,
depth: usize
) -> Result<(), XDocErr> where
W: Write,
[src]
&self,
writer: &mut W,
opts: &WriteOpts,
depth: usize
) -> Result<(), XDocErr> where
W: Write,
Write the element to the Write
object.
Trait Implementations
impl Clone for Element
[src]
impl Debug for Element
[src]
impl Default for Element
[src]
impl Display for Element
[src]
impl Eq for Element
[src]
impl Hash for Element
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Element
[src]
pub fn cmp(&self, other: &Element) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Element> for Element
[src]
impl PartialOrd<Element> for Element
[src]
pub fn partial_cmp(&self, other: &Element) -> Option<Ordering>
[src]
pub fn lt(&self, other: &Element) -> bool
[src]
pub fn le(&self, other: &Element) -> bool
[src]
pub fn gt(&self, other: &Element) -> bool
[src]
pub fn ge(&self, other: &Element) -> bool
[src]
impl StructuralEq for Element
[src]
impl StructuralPartialEq for Element
[src]
Auto Trait Implementations
impl RefUnwindSafe for Element
[src]
impl Send for Element
[src]
impl Sync for Element
[src]
impl Unpin for Element
[src]
impl UnwindSafe for Element
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,