Struct dom_query::Document

source ·
pub struct Document {
    pub errors: Vec<Cow<'static, str>>,
    pub quirks_mode: QuirksMode,
    /* private fields */
}
Expand description

Document represents an HTML document to be manipulated.

Fields§

§errors: Vec<Cow<'static, str>>

Errors that occurred during parsing.

§quirks_mode: QuirksMode

The document’s quirks mode.

Implementations§

source§

impl Document

source

pub fn root(&self) -> NodeRef<'_, NodeData>

Return the underlying root document node.

source§

impl Document

source

pub fn html(&self) -> StrTendril

Gets the HTML contents of the document. It includes the text and comment nodes.

source

pub fn text(&self) -> StrTendril

Gets the text content of the document.

source§

impl Document

source

pub fn select(&self, sel: &str) -> Selection<'_>

Gets the descendants of the root document node in the current, filter by a selector. It returns a new selection object containing these matched elements.

§Panics

Panics if failed to parse the given CSS selector.

source

pub fn nip(&self, sel: &str) -> Selection<'_>

Alias for select, it gets the descendants of the root document node in the current, filter by a selector. It returns a new selection object containing these matched elements.

§Panics

Panics if failed to parse the given CSS selector.

source

pub fn try_select(&self, sel: &str) -> Option<Selection<'_>>

Gets the descendants of the root document node in the current, filter by a selector. It returns a new selection object containing these matched elements.

source

pub fn select_matcher<'a>(&'a self, matcher: &'a Matcher) -> Selection<'a>

Gets the descendants of the root document node in the current, filter by a matcher. It returns a new selection object containing these matched elements.

Trait Implementations§

source§

impl Default for Document

source§

fn default() -> Document

Returns the “default value” for a type. Read more
source§

impl From<&String> for Document

source§

fn from(html: &String) -> Document

Converts to this type from the input type.
source§

impl From<&str> for Document

source§

fn from(html: &str) -> Document

Converts to this type from the input type.
source§

impl From<Tendril<UTF8>> for Document

source§

fn from(html: StrTendril) -> Document

Converts to this type from the input type.
source§

impl TreeSink for Document

§

type Output = Document

The overall result of parsing. Read more
source§

fn finish(self) -> Self

Consume this sink and return the overall result of parsing. Read more
§

type Handle = NodeId

Handle is a reference to a DOM node. The tree builder requires that a Handle implements Clone to get another reference to the same node.
source§

fn parse_error(&mut self, msg: Cow<'static, str>)

Signal a parse error.
source§

fn get_document(&mut self) -> NodeId

Get a handle to the Document node.
source§

fn get_template_contents(&mut self, target: &NodeId) -> NodeId

Get a handle to a template’s template contents. The tree builder promises this will never be called with something else than a template element.
source§

fn set_quirks_mode(&mut self, mode: QuirksMode)

Set the document’s quirks mode.
source§

fn same_node(&self, x: &NodeId, y: &NodeId) -> bool

Do two handles refer to the same node?
source§

fn elem_name(&self, target: &NodeId) -> ExpandedName<'_>

What is the name of this element? Read more
source§

fn create_element( &mut self, name: QualName, attrs: Vec<Attribute>, flags: ElementFlags ) -> NodeId

Create an element. Read more
source§

fn create_comment(&mut self, text: StrTendril) -> NodeId

Create a comment node.
source§

fn create_pi(&mut self, target: StrTendril, data: StrTendril) -> NodeId

Create a Processing Instruction node.
source§

fn append(&mut self, parent: &NodeId, child: NodeOrText<NodeId>)

Append a node as the last child of the given node. If this would produce adjacent sibling text nodes, it should concatenate the text instead. Read more
source§

fn append_before_sibling(&mut self, sibling: &NodeId, child: NodeOrText<NodeId>)

Append a node as the sibling immediately before the given node. Read more
source§

fn append_based_on_parent_node( &mut self, element: &NodeId, prev_element: &NodeId, child: NodeOrText<NodeId> )

When the insertion point is decided by the existence of a parent node of the element, we consider both possibilities and send the element which will be used if a parent node exists, along with the element to be used if there isn’t one.
source§

fn append_doctype_to_document( &mut self, name: StrTendril, public_id: StrTendril, system_id: StrTendril )

Append a DOCTYPE element to the Document node.
source§

fn add_attrs_if_missing(&mut self, target: &NodeId, attrs: Vec<Attribute>)

Add each attribute to the given element, if no attribute with that name already exists. The tree builder promises this will never be called with something else than an element.
source§

fn remove_from_parent(&mut self, target: &NodeId)

Detach the given node from its parent.
source§

fn reparent_children(&mut self, node: &NodeId, new_parent: &NodeId)

Remove all the children from node and append them to new_parent.
source§

fn mark_script_already_started(&mut self, _node: &Self::Handle)

Mark a HTML <script> as “already started”.
source§

fn pop(&mut self, _node: &Self::Handle)

Indicate that a node was popped off the stack of open elements.
source§

fn associate_with_form( &mut self, _target: &Self::Handle, _form: &Self::Handle, _nodes: (&Self::Handle, Option<&Self::Handle>) )

Associate the given form-associatable element with the form element
source§

fn is_mathml_annotation_xml_integration_point( &self, _handle: &Self::Handle ) -> bool

Returns true if the adjusted current node is an HTML integration point and the token is a start tag.
source§

fn set_current_line(&mut self, _line_number: u64)

Called whenever the line number changes.
source§

fn complete_script(&mut self, _node: &Self::Handle) -> NextParserState

Indicate that a script element is complete.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.