pub struct Document { /* private fields */ }Expand description
A parsed HTML document backed by an arena.
Provides access to the root node and convenience methods for querying the DOM tree.
Implementations§
Source§impl Document
impl Document
Sourcepub fn to_html(&self) -> String
pub fn to_html(&self) -> String
Serialize the entire document back to an HTML string.
This produces the outer HTML of the root node, which includes all children with proper entity escaping for text and attribute values.
§Example
use fhp_tree::parse;
let doc = parse("<p>Hello & world</p>").unwrap();
let html = doc.to_html();
assert!(html.contains("&"));Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Total number of nodes in the document.
Trait Implementations§
Source§impl Selectable for Document
impl Selectable for Document
Source§fn select(&self, css: &str) -> Result<Selection<'_>, SelectorError>
fn select(&self, css: &str) -> Result<Selection<'_>, SelectorError>
Select all nodes matching a CSS selector. Read more
Source§fn select_compiled(
&self,
sel: &CompiledSelector,
) -> Result<Selection<'_>, SelectorError>
fn select_compiled( &self, sel: &CompiledSelector, ) -> Result<Selection<'_>, SelectorError>
Select all nodes matching a pre-compiled CSS selector. Read more
Source§fn select_first_compiled(
&self,
sel: &CompiledSelector,
) -> Result<Option<NodeRef<'_>>, SelectorError>
fn select_first_compiled( &self, sel: &CompiledSelector, ) -> Result<Option<NodeRef<'_>>, SelectorError>
Select the first node matching a pre-compiled CSS selector.
Source§fn select_first(&self, css: &str) -> Result<Option<NodeRef<'_>>, SelectorError>
fn select_first(&self, css: &str) -> Result<Option<NodeRef<'_>>, SelectorError>
Select the first node matching a CSS selector.
Source§fn find_by_tag(&self, tag: Tag) -> Selection<'_>
fn find_by_tag(&self, tag: Tag) -> Selection<'_>
Find all elements with the given tag.
Source§fn find_by_id(&self, id: &str) -> Option<NodeRef<'_>>
fn find_by_id(&self, id: &str) -> Option<NodeRef<'_>>
Find an element by its
id attribute. Read moreSource§fn find_by_class(&self, class: &str) -> Selection<'_>
fn find_by_class(&self, class: &str) -> Selection<'_>
Find all elements with the given CSS class.
Source§fn find_by_attr(&self, name: &str, value: &str) -> Selection<'_>
fn find_by_attr(&self, name: &str, value: &str) -> Selection<'_>
Find all elements with an attribute matching a value.
Source§fn xpath(&self, expr: &str) -> Result<XPathResult, XPathError>
fn xpath(&self, expr: &str) -> Result<XPathResult, XPathError>
Evaluate an XPath expression against the document. Read more
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
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
Mutably borrows from an owned value. Read more