Struct victoria_dom::DOM
[−]
[src]
pub struct DOM { /* fields omitted */ }
The HTML DOM
type
Methods
impl DOM
[src]
pub fn new(html: &str) -> DOM
[src]
Construct a new DOM
object and parse HTML.
use victoria_dom::DOM; let dom = DOM::new("<div id=\"title\">Hello</div>");
pub fn ancestors(&self, selector: Option<&str>) -> Vec<DOM>
[src]
Find all ancestor elements of the current element matching the optional CSS selector and return a Vector of DOM objects of these elements.
use victoria_dom::DOM; let dom = DOM::new("<html><body><div id=\"title\">Hello</div></body></html>"); let ancestors: Vec<_> = dom.at("div").unwrap().ancestors(None).iter().map(|x| x.tag().unwrap().to_string()).collect(); assert_eq!(ancestors, ["body", "html"]);
pub fn at(&self, selector: &str) -> Option<DOM>
[src]
Find first descendant element of the current element matching the CSS selector and return it as a DOM object,
or None
if none could be found.
pub fn tag(&self) -> Option<&str>
[src]
The current element tag name.
pub fn attrs(&self) -> BTreeMap<String, Option<String>>
[src]
The current element attribute2value map.
pub fn attr(&self, name: &str) -> Option<&str>
[src]
The current element attribute value, or None
if there are no attribute with the name or value.
pub fn childs(&self, selector: Option<&str>) -> Vec<DOM>
[src]
Find all child elements of the current element matching the CSS selector and return a Vector of DOM objects of these elements.
use victoria_dom::DOM; let dom = DOM::new("<div><div id=\"a\">A <span id=\"c\">C</span></div><div id=\"b\">B</div></div>"); let childs: Vec<_> = dom.at("div").unwrap().childs(None).iter().map(|x| x.attr("id").unwrap().to_string()).collect(); assert_eq!(childs, ["a", "b"]);
pub fn find(&self, selector: &str) -> Vec<DOM>
[src]
Find all descendant elements of the current element matching the CSS selector and return a Vector of DOM objects of these elements.
use victoria_dom::DOM; let dom = DOM::new("<div><div id=\"a\"><div id=\"c\">C</div></div><div id=\"b\">B</div></div>"); let elems: Vec<_> = dom.find("div[id]").iter().map(|x| x.attr("id").unwrap().to_string()).collect(); assert_eq!(elems, ["a", "c", "b"]);
pub fn matches(&self, selector: &str) -> bool
[src]
Check if the current element matches the CSS selector.
pub fn following(&self, selector: Option<&str>) -> Vec<DOM>
[src]
Find all sibling elements after the current element matching the CSS selector and return a Vector of DOM objects of these elements.
use victoria_dom::DOM; let dom = DOM::new("<div><div id=\"a\"><div id=\"c\">C</div></div><div id=\"b\">B</div></div>"); let elems: Vec<_> = dom.at("div#a").unwrap().following(None).iter().map(|x| x.attr("id").unwrap().to_string()).collect(); assert_eq!(elems, ["b"]);
pub fn next(&self) -> Option<DOM>
[src]
Return a DOM object for next sibling element, or None
if there are no more siblings.
pub fn preceding(&self, selector: Option<&str>) -> Vec<DOM>
[src]
Find all sibling elements before the current element matching the CSS selector and return a Vector of DOM objects of these elements.
use victoria_dom::DOM; let dom = DOM::new("<div><div id=\"a\"><div id=\"c\">C</div></div><div id=\"b\">B</div></div>"); let elems: Vec<_> = dom.at("div#b").unwrap().preceding(None).iter().map(|x| x.attr("id").unwrap().to_string()).collect(); assert_eq!(elems, ["a"]);
pub fn prev(&self) -> Option<DOM>
[src]
Return a DOM object for the previous sibling element, or None
if there are no more siblings.
pub fn parent(&self) -> Option<DOM>
[src]
Return a DOM object for the parent of the current element, or None
if this element has no parent.
pub fn to_string(&self) -> String
[src]
Render the current element and its content to HTML.
pub fn text(&self) -> String
[src]
Extract text content from the current element only (not including child elements) with smart whitespace trimming.
use victoria_dom::DOM; let dom = DOM::new("<div>foo\n<p>bar</p>baz\n</div>"); assert_eq!(dom.at("div").unwrap().text(), "foo baz");
pub fn rtext(&self) -> String
[src]
Extract text content from the current element only (not including child elements) without smart whitespace trimming.
use victoria_dom::DOM; let dom = DOM::new("<div>foo\n<p>bar</p>baz\n</div>"); assert_eq!(dom.at("div").unwrap().rtext(), "foo\nbaz\n");
pub fn text_all(&self) -> String
[src]
Extract text content from all descendant nodes of the current element with smart whitespace trimming.
use victoria_dom::DOM; let dom = DOM::new("<div>foo\n<p>bar</p>baz\n</div>"); assert_eq!(dom.at("div").unwrap().text_all(), "foo bar baz");
pub fn rtext_all(&self) -> String
[src]
Extract text content from all descendant nodes of the current element without smart whitespace trimming.
use victoria_dom::DOM; let dom = DOM::new("<div>foo\n<p>bar</p>baz\n</div>"); assert_eq!(dom.at("div").unwrap().rtext_all(), "foo\nbarbaz\n");
pub fn content(&self) -> String
[src]
Return content of the current element.
use victoria_dom::DOM; let dom = DOM::new("<div><b>Test</b></div>"); assert_eq!(dom.at("div").unwrap().content(), "<b>Test</b>");