Struct dae_parser::Element
source · [−]pub struct Element { /* private fields */ }
Expand description
A struct representing a DOM Element.
Implementations
sourceimpl Element
impl Element
sourcepub fn builder<S, NS>(name: S, namespace: NS) -> ElementBuilder where
S: AsRef<str>,
NS: Into<String>,
pub fn builder<S, NS>(name: S, namespace: NS) -> ElementBuilder where
S: AsRef<str>,
NS: Into<String>,
Return a builder for an Element
with the given name
.
Examples
use minidom::Element;
let elem = Element::builder("name", "namespace")
.attr("name", "value")
.append("inner")
.build();
assert_eq!(elem.name(), "name");
assert_eq!(elem.ns(), "namespace".to_owned());
assert_eq!(elem.attr("name"), Some("value"));
assert_eq!(elem.attr("inexistent"), None);
assert_eq!(elem.text(), "inner");
sourcepub fn bare<S, NS>(name: S, namespace: NS) -> Element where
S: Into<String>,
NS: Into<String>,
pub fn bare<S, NS>(name: S, namespace: NS) -> Element where
S: Into<String>,
NS: Into<String>,
Returns a bare minimum Element
with this name.
Examples
use minidom::Element;
let bare = Element::bare("name", "namespace");
assert_eq!(bare.name(), "name");
assert_eq!(bare.ns(), "namespace");
assert_eq!(bare.attr("name"), None);
assert_eq!(bare.text(), "");
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns a reference to the local name of this element (that is, without a possible prefix).
sourcepub fn attr(&self, name: &str) -> Option<&str>
pub fn attr(&self, name: &str) -> Option<&str>
Returns a reference to the value of the given attribute, if it exists, else None
.
sourcepub fn attrs(&self) -> Attrs<'_>
pub fn attrs(&self) -> Attrs<'_>
Returns an iterator over the attributes of this element.
Example
use minidom::Element;
let elm: Element = "<elem xmlns=\"ns1\" a=\"b\" />".parse().unwrap();
let mut iter = elm.attrs();
assert_eq!(iter.next().unwrap(), ("a", "b"));
assert_eq!(iter.next(), None);
sourcepub fn attrs_mut(&mut self) -> AttrsMut<'_>
pub fn attrs_mut(&mut self) -> AttrsMut<'_>
Returns an iterator over the attributes of this element, with the value being a mutable reference.
sourcepub fn set_attr<S, V>(&mut self, name: S, val: V) where
S: Into<String>,
V: IntoAttributeValue,
pub fn set_attr<S, V>(&mut self, name: S, val: V) where
S: Into<String>,
V: IntoAttributeValue,
Modifies the value of an attribute.
sourcepub fn is<'a, N, NS>(&self, name: N, namespace: NS) -> bool where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
pub fn is<'a, N, NS>(&self, name: N, namespace: NS) -> bool where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
Returns whether the element has the given name and namespace.
Examples
use minidom::{Element, NSChoice};
let elem = Element::builder("name", "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);
assert_eq!(elem.is("name", NSChoice::OneOf("namespace")), true);
assert_eq!(elem.is("name", NSChoice::OneOf("foo")), false);
assert_eq!(elem.is("name", NSChoice::AnyOf(&["foo", "namespace"])), true);
assert_eq!(elem.is("name", NSChoice::Any), true);
sourcepub fn has_ns<'a, NS>(&self, namespace: NS) -> bool where
NS: Into<NSChoice<'a>>,
pub fn has_ns<'a, NS>(&self, namespace: NS) -> bool where
NS: Into<NSChoice<'a>>,
Returns whether the element has the given namespace.
Examples
use minidom::{Element, NSChoice};
let elem = Element::builder("name", "namespace").build();
assert_eq!(elem.has_ns("namespace"), true);
assert_eq!(elem.has_ns("wrong"), false);
assert_eq!(elem.has_ns(NSChoice::OneOf("namespace")), true);
assert_eq!(elem.has_ns(NSChoice::OneOf("foo")), false);
assert_eq!(elem.has_ns(NSChoice::AnyOf(&["foo", "namespace"])), true);
assert_eq!(elem.has_ns(NSChoice::Any), true);
sourcepub fn from_reader<R>(reader: &mut Reader<R>) -> Result<Element, Error> where
R: BufRead,
pub fn from_reader<R>(reader: &mut Reader<R>) -> Result<Element, Error> where
R: BufRead,
Parse a document from an EventReader
.
sourcepub fn write_to<W>(&self, writer: &mut W) -> Result<(), Error> where
W: Write,
pub fn write_to<W>(&self, writer: &mut W) -> Result<(), Error> where
W: Write,
Output a document to a Writer
.
sourcepub fn write_to_decl<W>(&self, writer: &mut W) -> Result<(), Error> where
W: Write,
pub fn write_to_decl<W>(&self, writer: &mut W) -> Result<(), Error> where
W: Write,
Output a document to a Writer
.
sourcepub fn to_writer<W>(&self, writer: &mut Writer<W>) -> Result<(), Error> where
W: Write,
pub fn to_writer<W>(&self, writer: &mut Writer<W>) -> Result<(), Error> where
W: Write,
Output the document to quick-xml Writer
sourcepub fn to_writer_decl<W>(&self, writer: &mut Writer<W>) -> Result<(), Error> where
W: Write,
pub fn to_writer_decl<W>(&self, writer: &mut Writer<W>) -> Result<(), Error> where
W: Write,
Output the document to quick-xml Writer
sourcepub fn write_to_inner<W>(
&self,
writer: &mut Writer<W>,
all_prefixes: &mut BTreeMap<Option<String>, String>
) -> Result<(), Error> where
W: Write,
pub fn write_to_inner<W>(
&self,
writer: &mut Writer<W>,
all_prefixes: &mut BTreeMap<Option<String>, String>
) -> Result<(), Error> where
W: Write,
Like write_to()
but without the <?xml?>
prelude
sourcepub fn nodes(&self) -> Iter<'_, Node>
pub fn nodes(&self) -> Iter<'_, Node>
Returns an iterator over references to every child node of this element.
Examples
use minidom::Element;
let elem: Element = "<root xmlns=\"ns1\">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);
sourcepub fn nodes_mut(&mut self) -> IterMut<'_, Node>
pub fn nodes_mut(&mut self) -> IterMut<'_, Node>
Returns an iterator over mutable references to every child node of this element.
sourcepub fn children(&self) -> Children<'_>
pub fn children(&self) -> Children<'_>
Returns an iterator over references to every child element of this element.
Examples
use minidom::Element;
let elem: Element = "<root xmlns=\"ns1\">hello<child1 xmlns=\"ns1\"/>this<child2 xmlns=\"ns1\"/>is<child3 xmlns=\"ns1\"/>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);
sourcepub fn children_mut(&mut self) -> ChildrenMut<'_>
pub fn children_mut(&mut self) -> ChildrenMut<'_>
Returns an iterator over mutable references to every child element of this element.
sourcepub fn texts(&self) -> Texts<'_>
pub fn texts(&self) -> Texts<'_>
Returns an iterator over references to every text node of this element.
Examples
use minidom::Element;
let elem: Element = "<root xmlns=\"ns1\">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);
sourcepub fn texts_mut(&mut self) -> TextsMut<'_>
pub fn texts_mut(&mut self) -> TextsMut<'_>
Returns an iterator over mutable references to every text node of this element.
sourcepub fn append_child(&mut self, child: Element) -> &mut Element
pub fn append_child(&mut self, child: Element) -> &mut Element
Appends a child node to the Element
, returning the appended node.
Examples
use minidom::Element;
let mut elem = Element::bare("root", "ns1");
assert_eq!(elem.children().count(), 0);
elem.append_child(Element::bare("child", "ns1"));
{
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", "ns1"));
assert_eq!(child.name(), "new");
sourcepub fn append_text_node<S>(&mut self, child: S) where
S: Into<String>,
pub fn append_text_node<S>(&mut self, child: S) where
S: Into<String>,
Appends a text node to an Element
.
Examples
use minidom::Element;
let mut elem = Element::bare("node", "ns1");
assert_eq!(elem.text(), "");
elem.append_text_node("text");
assert_eq!(elem.text(), "text");
sourcepub fn append_node(&mut self, node: Node)
pub fn append_node(&mut self, node: Node)
Appends a node to an Element
.
Examples
use minidom::{Element, Node};
let mut elem = Element::bare("node", "ns1");
elem.append_node(Node::Text("hello".to_owned()));
assert_eq!(elem.text(), "hello");
sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Returns the concatenation of all text nodes in the Element
.
Examples
use minidom::Element;
let elem: Element = "<node xmlns=\"ns1\">hello,<split /> world!</node>".parse().unwrap();
assert_eq!(elem.text(), "hello, world!");
sourcepub fn get_child<'a, N, NS>(&self, name: N, namespace: NS) -> Option<&Element> where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
pub fn get_child<'a, N, NS>(&self, name: N, namespace: NS) -> Option<&Element> where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
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, NSChoice};
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);
sourcepub fn get_child_mut<'a, N, NS>(
&mut self,
name: N,
namespace: NS
) -> Option<&mut Element> where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
pub fn get_child_mut<'a, N, NS>(
&mut self,
name: N,
namespace: NS
) -> Option<&mut Element> where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
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
.
sourcepub fn has_child<'a, N, NS>(&self, name: N, namespace: NS) -> bool where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
pub fn has_child<'a, N, NS>(&self, name: N, namespace: NS) -> bool where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
Returns whether a specific child with this name and namespace exists in the direct
descendants of the Element
.
Examples
use minidom::{Element, NSChoice};
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);
sourcepub fn remove_child<'a, N, NS>(
&mut self,
name: N,
namespace: NS
) -> Option<Element> where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
pub fn remove_child<'a, N, NS>(
&mut self,
name: N,
namespace: NS
) -> Option<Element> where
N: AsRef<str>,
NS: Into<NSChoice<'a>>,
Removes the first child with this name and namespace, if it exists, and returns an
Option<Element>
containing this child if it succeeds.
Returns None
if no child matches this name and namespace.
Examples
use minidom::{Element, NSChoice};
let mut elem: Element = r#"<node xmlns="ns"><a /><a xmlns="other_ns" /><b /></node>"#.parse().unwrap();
assert!(elem.remove_child("a", "ns").unwrap().is("a", "ns"));
assert!(elem.remove_child("a", "ns").is_none());
assert!(elem.remove_child("inexistent", "inexistent").is_none());
Trait Implementations
impl Eq for Element
impl StructuralEq for Element
Auto Trait Implementations
impl RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl UnwindSafe for Element
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more