Struct minidom::element::Element
[−]
[src]
pub struct Element { /* fields omitted */ }
A struct representing a DOM Element.
Methods
impl Element
[src]
fn builder<S: AsRef<str>>(name: S) -> ElementBuilder
[src]
Return a builder for an Element
with the given name
.
Examples
use minidom::Element; let elem = Element::builder("name") .ns("namespace") .attr("name", "value") .append("inner") .build(); assert_eq!(elem.name(), "name"); assert_eq!(elem.ns(), Some("namespace".to_owned())); assert_eq!(elem.attr("name"), Some("value")); assert_eq!(elem.attr("inexistent"), None); assert_eq!(elem.text(), "inner");
fn bare<S: Into<String>>(name: S) -> Element
[src]
Returns a bare minimum Element
with this name.
Examples
use minidom::Element; let bare = Element::bare("name"); assert_eq!(bare.name(), "name"); assert_eq!(bare.ns(), None); assert_eq!(bare.attr("name"), None); assert_eq!(bare.text(), "");
fn name(&self) -> &str
[src]
Returns a reference to the name of this element.
fn prefix(&self) -> Option<&str>
[src]
Returns a reference to the prefix of this element.
Examples
use minidom::Element; let elem = Element::builder("prefix:name") .build(); assert_eq!(elem.name(), "name"); assert_eq!(elem.prefix(), Some("prefix"));
fn ns(&self) -> Option<String>
[src]
Returns a reference to the namespace of this element, if it has one, else None
.
fn attr(&self, name: &str) -> Option<&str>
[src]
Returns a reference to the value of the given attribute, if it exists, else None
.
fn attrs(&self) -> Attrs
[src]
Returns an iterator over the attributes of this element.
Example
use minidom::Element; let elm: Element = "<elem a=\"b\" />".parse().unwrap(); let mut iter = elm.attrs(); assert_eq!(iter.next().unwrap(), ("a", "b")); assert_eq!(iter.next(), None);
fn attrs_mut(&mut self) -> AttrsMut
[src]
Returns an iterator over the attributes of this element, with the value being a mutable reference.
fn set_attr<S: Into<String>, V: IntoAttributeValue>(&mut self, name: S, val: V)
[src]
Modifies the value of an attribute.
fn is<N: AsRef<str>, NS: AsRef<str>>(&self, name: N, namespace: NS) -> bool
[src]
Returns whether the element has the given name and namespace.
Examples
use minidom::Element; let elem = Element::builder("name").ns("namespace").build(); assert_eq!(elem.is("name", "namespace"), true); assert_eq!(elem.is("name", "wrong"), false); assert_eq!(elem.is("wrong", "namespace"), false); assert_eq!(elem.is("wrong", "wrong"), false);
fn has_ns<NS: AsRef<str>>(&self, namespace: NS) -> bool
[src]
Returns whether the element has the given namespace.
Examples
use minidom::Element; let elem = Element::builder("name").ns("namespace").build(); assert_eq!(elem.has_ns("namespace"), true); assert_eq!(elem.has_ns("wrong"), false);
fn from_reader<R: BufRead>(reader: &mut EventReader<R>) -> Result<Element>
[src]
Parse a document from an EventReader
.
fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>
[src]
Output a document to a Writer
.
fn to_writer<W: Write>(&self, writer: &mut EventWriter<W>) -> Result<()>
[src]
Output the document to quick-xml Writer
fn write_to_inner<W: Write>(&self, writer: &mut EventWriter<W>) -> Result<()>
[src]
Like write_to()
but without the <?xml?>
prelude
fn nodes(&self) -> Nodes
[src]
Returns an iterator over references to every child node of this element.
Examples
use minidom::Element; let elem: Element = "<root>a<c1 />b<c2 />c</root>".parse().unwrap(); let mut iter = elem.nodes(); assert_eq!(iter.next().unwrap().as_text().unwrap(), "a"); assert_eq!(iter.next().unwrap().as_element().unwrap().name(), "c1"); assert_eq!(iter.next().unwrap().as_text().unwrap(), "b"); assert_eq!(iter.next().unwrap().as_element().unwrap().name(), "c2"); assert_eq!(iter.next().unwrap().as_text().unwrap(), "c"); assert_eq!(iter.next(), None);
fn nodes_mut(&mut self) -> NodesMut
[src]
Returns an iterator over mutable references to every child node of this element.
fn children(&self) -> Children
[src]
Returns an iterator over references to every child element of this element.
Examples
use minidom::Element; let elem: Element = "<root>hello<child1 />this<child2 />is<child3 />ignored</root>".parse().unwrap(); let mut iter = elem.children(); assert_eq!(iter.next().unwrap().name(), "child1"); assert_eq!(iter.next().unwrap().name(), "child2"); assert_eq!(iter.next().unwrap().name(), "child3"); assert_eq!(iter.next(), None);
fn children_mut(&mut self) -> ChildrenMut
[src]
Returns an iterator over mutable references to every child element of this element.
fn texts(&self) -> Texts
[src]
Returns an iterator over references to every text node of this element.
Examples
use minidom::Element; let elem: Element = "<root>hello<c /> world!</root>".parse().unwrap(); let mut iter = elem.texts(); assert_eq!(iter.next().unwrap(), "hello"); assert_eq!(iter.next().unwrap(), " world!"); assert_eq!(iter.next(), None);
fn texts_mut(&mut self) -> TextsMut
[src]
Returns an iterator over mutable references to every text node of this element.
fn append_child(&mut self, child: Element) -> &mut Element
[src]
Appends a child node to the Element
, returning the appended node.
Examples
use minidom::Element; let mut elem = Element::bare("root"); assert_eq!(elem.children().count(), 0); elem.append_child(Element::bare("child")); { let mut iter = elem.children(); assert_eq!(iter.next().unwrap().name(), "child"); assert_eq!(iter.next(), None); } let child = elem.append_child(Element::bare("new")); assert_eq!(child.name(), "new");
fn append_text_node<S: Into<String>>(&mut self, child: S)
[src]
Appends a text node to an Element
.
Examples
use minidom::Element; let mut elem = Element::bare("node"); assert_eq!(elem.text(), ""); elem.append_text_node("text"); assert_eq!(elem.text(), "text");
fn append_comment_node<S: Into<String>>(&mut self, child: S)
[src]
Appends a comment node to an Element
.
Examples
use minidom::Element; let mut elem = Element::bare("node"); elem.append_comment_node("comment");
fn append_node(&mut self, node: Node)
[src]
Appends a node to an Element
.
Examples
use minidom::{Element, Node}; let mut elem = Element::bare("node"); elem.append_node(Node::Text("hello".to_owned())); assert_eq!(elem.text(), "hello");
fn text(&self) -> String
[src]
Returns the concatenation of all text nodes in the Element
.
Examples
use minidom::Element; let elem: Element = "<node>hello,<split /> world!</node>".parse().unwrap(); assert_eq!(elem.text(), "hello, world!");
fn get_child<N: AsRef<str>, NS: AsRef<str>>(
&self,
name: N,
namespace: NS
) -> Option<&Element>
[src]
&self,
name: N,
namespace: NS
) -> Option<&Element>
Returns a reference to the first child element with the specific name and namespace, if it
exists in the direct descendants of this Element
, else returns None
.
Examples
use minidom::Element; let elem: Element = r#"<node xmlns="ns"><a /><a xmlns="other_ns" /><b /></node>"#.parse().unwrap(); assert!(elem.get_child("a", "ns").unwrap().is("a", "ns")); assert!(elem.get_child("a", "other_ns").unwrap().is("a", "other_ns")); assert!(elem.get_child("b", "ns").unwrap().is("b", "ns")); assert_eq!(elem.get_child("c", "ns"), None); assert_eq!(elem.get_child("b", "other_ns"), None); assert_eq!(elem.get_child("a", "inexistent_ns"), None);
fn get_child_mut<N: AsRef<str>, NS: AsRef<str>>(
&mut self,
name: N,
namespace: NS
) -> Option<&mut Element>
[src]
&mut self,
name: N,
namespace: NS
) -> Option<&mut Element>
Returns a mutable reference to the first child element with the specific name and namespace,
if it exists in the direct descendants of this Element
, else returns None
.
fn has_child<N: AsRef<str>, NS: AsRef<str>>(
&self,
name: N,
namespace: NS
) -> bool
[src]
&self,
name: N,
namespace: NS
) -> bool
Returns whether a specific child with this name and namespace exists in the direct
descendants of the Element
.
Examples
use minidom::Element; let elem: Element = r#"<node xmlns="ns"><a /><a xmlns="other_ns" /><b /></node>"#.parse().unwrap(); assert_eq!(elem.has_child("a", "other_ns"), true); assert_eq!(elem.has_child("a", "ns"), true); assert_eq!(elem.has_child("a", "inexistent_ns"), false); assert_eq!(elem.has_child("b", "ns"), true); assert_eq!(elem.has_child("b", "other_ns"), false); assert_eq!(elem.has_child("b", "inexistent_ns"), false);
Trait Implementations
impl Clone for Element
[src]
fn clone(&self) -> Element
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq for Element
[src]
fn eq(&self, __arg_0: &Element) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Element) -> bool
[src]
This method tests for !=
.