Table of Contents

Class Document

Namespace
AngleSharp.Dom
Assembly
AngleSharp.dll

Represents a document node.

public abstract class Document : Node, IEquatable<INode>, IDocument, INode, IEventTarget, IMarkupFormattable, IParentNode, IGlobalEventHandlers, IDocumentStyle, INonElementParentNode, IDisposable
Inheritance
Document
Implements
Inherited Members
Extension Methods

Constructors

Document(IBrowsingContext, TextSource)

public Document(IBrowsingContext context, TextSource source)

Parameters

context IBrowsingContext
source TextSource

Properties

ActiveElement

Gets the currently focused element, that is, the element that will get keystroke events if the user types any.

public IElement? ActiveElement { get; }

Property Value

IElement

All

Gets a list of all elements in the document.

public IHtmlAllCollection All { get; }

Property Value

IHtmlAllCollection

Anchors

Gets a list of all of the anchors in the document.

public IHtmlCollection<IHtmlAnchorElement> Anchors { get; }

Property Value

IHtmlCollection<IHtmlAnchorElement>

Body

Gets the body element.

public IHtmlElement? Body { get; set; }

Property Value

IHtmlElement

CharacterSet

Gets the character encoding of the current document.

public string CharacterSet { get; }

Property Value

string

ChildElementCount

Gets the number of child elements.

public int ChildElementCount { get; }

Property Value

int

Children

Gets the child elements.

public IHtmlCollection<IElement> Children { get; }

Property Value

IHtmlCollection<IElement>

Commands

Gets a list of the commands (menu item, button, and link elements) within the current document.

public IHtmlCollection<IElement> Commands { get; }

Property Value

IHtmlCollection<IElement>

CompatMode

Gets a value to indicate whether the document is rendered in Quirks mode (BackComp) or Strict mode (CSS1Compat).

public string CompatMode { get; }

Property Value

string

ContentType

Gets the Content-Type from the MIME Header of the current document.

public string ContentType { get; protected set; }

Property Value

string

Context

Gets the browsing context to use.

public IBrowsingContext Context { get; }

Property Value

IBrowsingContext

Gets or sets the document cookie.

public string Cookie { get; set; }

Property Value

string

CurrentScript

Gets the script element which is currently being processed.

public IHtmlScriptElement? CurrentScript { get; }

Property Value

IHtmlScriptElement

DefaultView

Gets the window object associated with the document or null if none available.

public IWindow DefaultView { get; }

Property Value

IWindow

DesignMode

Gets or sets whether the entire document is editable.

public string DesignMode { get; set; }

Property Value

string

Direction

Gets or sets the value of the dir attribute.

public string? Direction { get; set; }

Property Value

string

Doctype

Gets the document type.

public IDocumentType Doctype { get; }

Property Value

IDocumentType

DocumentElement

Gets the root element of the document.

public abstract IElement DocumentElement { get; }

Property Value

IElement

DocumentUri

Gets the URI of the current document.

public string DocumentUri { get; protected set; }

Property Value

string

DocumentUrl

public Url DocumentUrl { get; }

Property Value

Url

Domain

Gets or sets the domain portion of the origin of the current document.

public string Domain { get; set; }

Property Value

string

Entities

Gets the associated entity provider.

public abstract IEntityProvider Entities { get; }

Property Value

IEntityProvider

FirstElementChild

Gets the first child element of this element.

public IElement? FirstElementChild { get; }

Property Value

IElement

Forms

Gets the forms in the document.

public IHtmlCollection<IHtmlFormElement> Forms { get; }

Property Value

IHtmlCollection<IHtmlFormElement>

Head

Gets or sets the head element.

public IHtmlHeadElement? Head { get; }

Property Value

IHtmlHeadElement

Images

Gets the images in the document.

public IHtmlCollection<IHtmlImageElement> Images { get; }

Property Value

IHtmlCollection<IHtmlImageElement>

Implementation

Gets the DOM implementation associated with the current document.

public IImplementation Implementation { get; }

Property Value

IImplementation

ImportAncestor

Gets the import ancestor, if any.

public IDocument? ImportAncestor { get; }

Property Value

IDocument

IsAsync

public bool IsAsync { get; }

Property Value

bool

IsLoading

public bool IsLoading { get; }

Property Value

bool

IsReady

public bool IsReady { get; }

Property Value

bool

LastElementChild

Gets the last child element of this element.

public IElement? LastElementChild { get; }

Property Value

IElement

LastModified

Gets the date of the last modification.

public string? LastModified { get; protected set; }

Property Value

string

LastStyleSheetSet

Gets the last stylesheet set.

public string? LastStyleSheetSet { get; }

Property Value

string

Gets a collection of all area and anchor elements in a document with a value for the href attribute.

public IHtmlCollection<IElement> Links { get; }

Property Value

IHtmlCollection<IElement>

Location

Gets the current location of the document.

public ILocation Location { get; }

Property Value

ILocation

Loop

public IEventLoop? Loop { get; }

Property Value

IEventLoop

Origin

Gets the Unicode serialization of document's origin.

public string? Origin { get; }

Property Value

string

Plugins

Gets a list of the embed elements within the current document.

public IHtmlCollection<IHtmlEmbedElement> Plugins { get; }

Property Value

IHtmlCollection<IHtmlEmbedElement>

PreferredStyleSheetSet

Gets the preferred stylesheet set.

public string? PreferredStyleSheetSet { get; }

Property Value

string

ReadyState

Gets the current ready state of the document.

public DocumentReadyState ReadyState { get; protected set; }

Property Value

DocumentReadyState

Referrer

Gets the referer to that pointed to the current document.

public string Referrer { get; protected set; }

Property Value

string

Scripts

Gets the scripts in the document.

public IHtmlCollection<IHtmlScriptElement> Scripts { get; }

Property Value

IHtmlCollection<IHtmlScriptElement>

SelectedStyleSheetSet

Gets or sets the selected set of stylesheets.

public string? SelectedStyleSheetSet { get; set; }

Property Value

string

Source

Gets the underlying source.

public TextSource Source { get; }

Property Value

TextSource

StatusCode

Gets the status code of the server's response, if any.

public HttpStatusCode StatusCode { get; }

Property Value

HttpStatusCode

StyleSheetSets

Gets a live list of all of the currently-available style sheet sets.

public IStringList StyleSheetSets { get; }

Property Value

IStringList

StyleSheets

Gets a list of stylesheet objects for stylesheets explicitly linked into or embedded in a document.

public IStyleSheetList StyleSheets { get; }

Property Value

IStyleSheetList

Title

Gets or sets the title of the document.

public string? Title { get; set; }

Property Value

string

Url

Gets a string containing the URL of the current document.

public string Url { get; }

Property Value

string

Methods

AddImportUrl(Uri)

Adds a Uri to the list of imported Uris.

public bool AddImportUrl(Uri uri)

Parameters

uri Uri

The Uri to add.

Returns

bool

True if uri is not null or previously added, false otherwise.

Adopt(INode)

Adopts a node from an external document. The node and its subtree is removed from the document it's in (if any), and its ownerDocument is changed to the current document. The node can then be inserted into the current document. The new node's parentNode is null, since it has not yet been inserted into the document tree.

public INode Adopt(INode externalNode)

Parameters

externalNode INode

The node from another document to be adopted.

Returns

INode

The adopted node that can be used in the current document.

Append(params INode[])

Appends nodes to current document.

public void Append(params INode[] nodes)

Parameters

nodes INode[]

The nodes to append.

Clear()

Clears the whole document without any notification.

public void Clear()

CloneDocument(Document, bool)

protected void CloneDocument(Document document, bool deep)

Parameters

document Document
deep bool

CreateAttribute(string)

Creates an Attr of the given name.

public IAttr CreateAttribute(string localName)

Parameters

localName string

Returns

IAttr

A new Attr object with the nodeName attribute set to name, and localName, prefix, and namespaceURI set to null. The value of the attribute is the empty string.

CreateAttribute(string?, string)

Creates an attribute of the given qualified name and namespace URI.

public IAttr CreateAttribute(string? namespaceUri, string qualifiedName)

Parameters

namespaceUri string

The namespace URI of the attribute to create.

qualifiedName string

Returns

IAttr

A new Attr object.

CreateComment(string)

Creates a new comment node, and returns it.

public IComment CreateComment(string data)

Parameters

data string

A string containing the data to be added to the Comment.

Returns

IComment

The new comment.

CreateDocumentFragment()

Creates an empty DocumentFragment object.

public IDocumentFragment CreateDocumentFragment()

Returns

IDocumentFragment

The new document fragment.

CreateElement(string)

Creates a new element with the given tag name.

public IElement CreateElement(string localName)

Parameters

localName string

Returns

IElement

The created element object.

CreateElement(string?, string)

Creates a new element with the given tag name and namespace URI.

public IElement CreateElement(string? namespaceUri, string qualifiedName)

Parameters

namespaceUri string

Specifies the namespace URI to associate with the element.

qualifiedName string

Returns

IElement

The created element.

CreateElementFrom(string, string, NodeFlags)

Creates a new element in the current namespace from the infos.

public abstract Element CreateElementFrom(string name, string prefix, NodeFlags flags = NodeFlags.None)

Parameters

name string

The name of the new element.

prefix string

The optional prefix to use.

flags NodeFlags

The optional flags, if any.

Returns

Element

The created element.

CreateEvent(string)

Creates an event of the type specified.

public Event CreateEvent(string type)

Parameters

type string

Represents the type of event (e.g., uievent, event, customevent, ...) to be created.

Returns

Event

The event.

CreateNodeIterator(INode, FilterSettings, NodeFilter?)

Creates a new NodeIterator object.

public INodeIterator CreateNodeIterator(INode root, FilterSettings settings = FilterSettings.All, NodeFilter? filter = null)

Parameters

root INode

The root node at which to begin the NodeIterator's traversal.

settings FilterSettings

Indicates which nodes to iterate over.

filter NodeFilter

An optional callback function for filtering.

Returns

INodeIterator

The created node NodeIterator.

CreateProcessingInstruction(string, string)

Creates a ProcessingInstruction node given the specified name and data strings.

public IProcessingInstruction CreateProcessingInstruction(string target, string data)

Parameters

target string

The target part of the processing instruction.

data string

The data for the node.

Returns

IProcessingInstruction

The new processing instruction.

CreateRange()

Creates a new Range object.

public IRange CreateRange()

Returns

IRange

The range.

CreateTextNode(string)

Creates a new text node and returns it.

public IText CreateTextNode(string data)

Parameters

data string

A string containing the data to be put in the text node.

Returns

IText

The created text node.

CreateTreeWalker(INode, FilterSettings, NodeFilter?)

Creates a new TreeWalker object.

public ITreeWalker CreateTreeWalker(INode root, FilterSettings settings = FilterSettings.All, NodeFilter? filter = null)

Parameters

root INode

Is the root Node of this TreeWalker traversal.

settings FilterSettings

Indicates which nodes to iterate over.

filter NodeFilter

An optional callback function for filtering.

Returns

ITreeWalker

The created node TreeWalker.

DelayLoad(Task?)

Waits for the given task before raising the load event.

public void DelayLoad(Task? task)

Parameters

task Task

The task to wait for.

Dispose()

public void Dispose()

EnableStyleSheetsForSet(string)

Enables the stylesheets matching the specified name in the current style sheet set, and disables all other style sheets (except those without a title, which are always enabled).

public void EnableStyleSheetsForSet(string name)

Parameters

name string

The name of the sheets to enable.

GetElementById(string)

Returns the Element whose ID is given by elementId. If no such element exists, returns null. The behavior is not defined if more than one element have this ID.

public IElement? GetElementById(string elementId)

Parameters

elementId string

A case-sensitive string representing the unique ID of the element being sought.

Returns

IElement

The matching element.

GetElementsByClassName(string)

Returns a set of elements which have all the given class names.

public IHtmlCollection<IElement> GetElementsByClassName(string classNames)

Parameters

classNames string

A string representing the list of class names to match; class names are separated by whitespace.

Returns

IHtmlCollection<IElement>

A collection of elements.

GetElementsByName(string)

Returns a list of elements with a given name in the HTML document.

public IHtmlCollection<IElement> GetElementsByName(string name)

Parameters

name string

The value of the name attribute of the element.

Returns

IHtmlCollection<IElement>

A collection of HTML elements.

GetElementsByTagName(string)

Returns a NodeList of elements with the given tag name. The complete document is searched, including the root node.

public IHtmlCollection<IElement> GetElementsByTagName(string tagName)

Parameters

tagName string

A string representing the name of the elements. The special string "*" represents all elements.

Returns

IHtmlCollection<IElement>

A collection of elements in the order they appear in the tree.

GetElementsByTagName(string?, string)

Returns a list of elements with the given tag name belonging to the given namespace. The complete document is searched, including the root node.

public IHtmlCollection<IElement> GetElementsByTagName(string? namespaceURI, string tagName)

Parameters

namespaceURI string
tagName string

Either the local name of elements to look for or the special value "*", which matches all elements.

Returns

IHtmlCollection<IElement>

A collection of elements in the order they appear in the tree.

GetTitle()

protected virtual string GetTitle()

Returns

string

HasFocus()

Checks if the document is currently focused.

public bool HasFocus()

Returns

bool

True if the document is active and in the focus.

HasImported(Uri)

Checks if a document has already imported a Uri.

public bool HasImported(Uri uri)

Parameters

uri Uri

The Uri to check.

Returns

bool

True if already imported.

Import(INode, bool)

Creates a copy of a node from an external document that can be inserted into the current document.

public INode Import(INode externalNode, bool deep = true)

Parameters

externalNode INode

The node from another document to be imported.

deep bool

Optional argument, indicating whether the descendants of the imported node need to be imported.

Returns

INode

The new node that is imported into the document. The new node's parentNode is null, since it has not yet been inserted into the document tree.

Load(string)

Loads the document content from the given url.

public void Load(string url)

Parameters

url string

The url that hosts the content.

LocateNamespace(string)

protected override sealed string? LocateNamespace(string prefix)

Parameters

prefix string

Returns

string

LocatePrefix(string)

protected override sealed string? LocatePrefix(string namespaceUri)

Parameters

namespaceUri string

Returns

string

Open(string, string?)

Causes the Document to be replaced in-place, as if it was a new Document object, but reusing the previous object, which is then returned.

public IDocument Open(string type = "text/html", string? replace = null)

Parameters

type string

The new content type.

replace string

Special annotation to replace the history.

Returns

IDocument

Prepend(params INode[])

Prepends nodes to the current document.

public void Prepend(params INode[] nodes)

Parameters

nodes INode[]

The nodes to prepend.

QuerySelector(string)

Returns the first element within the document (using depth-first pre-order traversal of the document's nodes) that matches the specified group of selectors.

public IElement? QuerySelector(string selectors)

Parameters

selectors string

The group of selectors to use.

Returns

IElement

The found element.

QuerySelectorAll(string)

Returns a list of the elements within the document (using depth-first pre-order traversal of the document's nodes) that match the specified group of selectors.

public IHtmlCollection<IElement> QuerySelectorAll(string selectors)

Parameters

selectors string

The group of selectors to use.

Returns

IHtmlCollection<IElement>

A non-live NodeList of element objects.

SetTitle(string?)

protected abstract void SetTitle(string? value)

Parameters

value string

Setup(IResponse, MimeType, IDocument?)

Sets the document up with the given parameters.

public void Setup(IResponse response, MimeType contentType, IDocument? importAncestor)

Parameters

response IResponse

The received response.

contentType MimeType

The content-type.

importAncestor IDocument

The ancestor, if any.

Write(string)

Writes text to a document.

public void Write(string content)

Parameters

content string

The text to be written on the document.

WriteLine(string)

Writes a line of text to a document.

public void WriteLine(string content)

Parameters

content string

The text to be written on the document.

Events

Aborted

Event triggered after aborting.

public event DomEventHandler Aborted

Event Type

DomEventHandler

Blurred

Event triggered after losing focus.

public event DomEventHandler Blurred

Event Type

DomEventHandler

CanPlay

Event triggered when the media can be played.

public event DomEventHandler CanPlay

Event Type

DomEventHandler

CanPlayThrough

Event triggered when the media can be fully played.

public event DomEventHandler CanPlayThrough

Event Type

DomEventHandler

Cancelled

Event triggered after cancelling.

public event DomEventHandler Cancelled

Event Type

DomEventHandler

Changed

Event triggered after the value changed.

public event DomEventHandler Changed

Event Type

DomEventHandler

Clicked

Event triggered after being clicked.

public event DomEventHandler Clicked

Event Type

DomEventHandler

CueChanged

Event triggered after changing the cue.

public event DomEventHandler CueChanged

Event Type

DomEventHandler

DoubleClick

Event triggered after performing a double click.

public event DomEventHandler DoubleClick

Event Type

DomEventHandler

Drag

Event triggered after starting to be dragged.

public event DomEventHandler Drag

Event Type

DomEventHandler

DragEnd

Event triggered after being dragged.

public event DomEventHandler DragEnd

Event Type

DomEventHandler

DragEnter

Event triggered after entering in dragging mode.

public event DomEventHandler DragEnter

Event Type

DomEventHandler

DragExit

Event triggered after exiting the dragging mode.

public event DomEventHandler DragExit

Event Type

DomEventHandler

DragLeave

Event triggered after leaving in dragging mode.

public event DomEventHandler DragLeave

Event Type

DomEventHandler

DragOver

Event triggered after hovering in dragging mode.

public event DomEventHandler DragOver

Event Type

DomEventHandler

DragStart

Event triggered after starting to drag.

public event DomEventHandler DragStart

Event Type

DomEventHandler

Dropped

Event triggered after dropping.

public event DomEventHandler Dropped

Event Type

DomEventHandler

DurationChanged

Event triggered when the media cursor changed.

public event DomEventHandler DurationChanged

Event Type

DomEventHandler

Emptied

Event triggered after being emptied.

public event DomEventHandler Emptied

Event Type

DomEventHandler

Ended

Event triggered after the media ended.

public event DomEventHandler Ended

Event Type

DomEventHandler

Error

Event triggered after an error occurred.

public event DomEventHandler Error

Event Type

DomEventHandler

Focused

Event triggered after receiving focus.

public event DomEventHandler Focused

Event Type

DomEventHandler

Input

Event triggered after input has happend.

public event DomEventHandler Input

Event Type

DomEventHandler

Invalid

Event triggered after validation failed.

public event DomEventHandler Invalid

Event Type

DomEventHandler

KeyDown

Event triggered after key down.

public event DomEventHandler KeyDown

Event Type

DomEventHandler

KeyPress

Event triggered after key press.

public event DomEventHandler KeyPress

Event Type

DomEventHandler

KeyUp

Event triggered after key up.

public event DomEventHandler KeyUp

Event Type

DomEventHandler

Loaded

Event triggered after the content has been fully loaded.

public event DomEventHandler Loaded

Event Type

DomEventHandler

LoadedData

Event triggered after the data has been loaded.

public event DomEventHandler LoadedData

Event Type

DomEventHandler

LoadedMetadata

Event triggered after the meta data has been received.

public event DomEventHandler LoadedMetadata

Event Type

DomEventHandler

Loading

Event triggered when loading begins.

public event DomEventHandler Loading

Event Type

DomEventHandler

MouseDown

Event triggered after mouse down.

public event DomEventHandler MouseDown

Event Type

DomEventHandler

MouseEnter

Event triggered after mouse enter.

public event DomEventHandler MouseEnter

Event Type

DomEventHandler

MouseLeave

Event triggered after mouse leave.

public event DomEventHandler MouseLeave

Event Type

DomEventHandler

MouseMove

Event triggered after mouse move.

public event DomEventHandler MouseMove

Event Type

DomEventHandler

MouseOut

Event triggered after mouse out.

public event DomEventHandler MouseOut

Event Type

DomEventHandler

MouseOver

Event triggered after mouse over.

public event DomEventHandler MouseOver

Event Type

DomEventHandler

MouseUp

Event triggered after mouse up.

public event DomEventHandler MouseUp

Event Type

DomEventHandler

MouseWheel

Event triggered after mouse wheel.

public event DomEventHandler MouseWheel

Event Type

DomEventHandler

Paused

Event triggered after the media paused.

public event DomEventHandler Paused

Event Type

DomEventHandler

Played

Event triggered after the media started.

public event DomEventHandler Played

Event Type

DomEventHandler

Playing

Event triggered before the media started.

public event DomEventHandler Playing

Event Type

DomEventHandler

Progress

Event triggered after progress.

public event DomEventHandler Progress

Event Type

DomEventHandler

RateChanged

Event triggered after the rate changed.

public event DomEventHandler RateChanged

Event Type

DomEventHandler

ReadyStateChanged

Event triggered after the ready state changed.

public event DomEventHandler ReadyStateChanged

Event Type

DomEventHandler

Resetted

Event triggered after resetting the form.

public event DomEventHandler Resetted

Event Type

DomEventHandler

Resized

Event triggered after resizing the window.

public event DomEventHandler Resized

Event Type

DomEventHandler

Scrolled

Event triggered after scrolling has happened.

public event DomEventHandler Scrolled

Event Type

DomEventHandler

Seeked

Event triggered after seeking in the media stream.

public event DomEventHandler Seeked

Event Type

DomEventHandler

Seeking

Event triggered before seeking in the media stream.

public event DomEventHandler Seeking

Event Type

DomEventHandler

Selected

Event triggered after selected the element.

public event DomEventHandler Selected

Event Type

DomEventHandler

Shown

Event triggered after being shown.

public event DomEventHandler Shown

Event Type

DomEventHandler

Stalled

Event triggered after being stalled.

public event DomEventHandler Stalled

Event Type

DomEventHandler

Submitted

Event triggered after the form has been submitted.

public event DomEventHandler Submitted

Event Type

DomEventHandler

Suspended

Event triggered after suspending.

public event DomEventHandler Suspended

Event Type

DomEventHandler

TimeUpdated

Event triggered after the time updated.

public event DomEventHandler TimeUpdated

Event Type

DomEventHandler

Toggled

Event triggered after being toggled.

public event DomEventHandler Toggled

Event Type

DomEventHandler

VolumeChanged

Event triggered after the volume changed.

public event DomEventHandler VolumeChanged

Event Type

DomEventHandler

Waiting

Event triggered when waiting for input.

public event DomEventHandler Waiting

Event Type

DomEventHandler