Table of Contents

Interface IDocument

Namespace
AngleSharp.Dom
Assembly
AngleSharp.dll

The Document interface serves as an entry point to the web page's content.

[DomName("Document")]
public interface IDocument : INode, IEventTarget, IMarkupFormattable, IParentNode, IGlobalEventHandlers, IDocumentStyle, INonElementParentNode, IDisposable
Inherited Members
Extension Methods

Properties

ActiveElement

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

[DomName("activeElement")]
IElement? ActiveElement { get; }

Property Value

IElement

All

Gets a list of all elements in the document.

[DomName("all")]
IHtmlAllCollection All { get; }

Property Value

IHtmlAllCollection

Anchors

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

[DomName("anchors")]
IHtmlCollection<IHtmlAnchorElement> Anchors { get; }

Property Value

IHtmlCollection<IHtmlAnchorElement>

Body

Gets the body element.

[DomName("body")]
IHtmlElement? Body { get; set; }

Property Value

IHtmlElement

CharacterSet

Gets the character encoding of the current document.

[DomName("characterSet")]
string CharacterSet { get; }

Property Value

string

Commands

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

[DomName("commands")]
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).

[DomName("compatMode")]
string CompatMode { get; }

Property Value

string

ContentType

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

[DomName("contentType")]
string ContentType { get; }

Property Value

string

Context

Gets the browsing context to use.

IBrowsingContext Context { get; }

Property Value

IBrowsingContext

Gets or sets the document cookie.

[DomName("cookie")]
string Cookie { get; set; }

Property Value

string

CurrentScript

Gets the script element which is currently being processed.

[DomName("currentScript")]
IHtmlScriptElement? CurrentScript { get; }

Property Value

IHtmlScriptElement

DefaultView

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

[DomName("defaultView")]
IWindow? DefaultView { get; }

Property Value

IWindow

DesignMode

Gets or sets whether the entire document is editable.

[DomName("designMode")]
string DesignMode { get; set; }

Property Value

string

Direction

Gets or sets the value of the dir attribute.

[DomName("dir")]
string? Direction { get; set; }

Property Value

string

Doctype

Gets the document type.

[DomName("doctype")]
IDocumentType Doctype { get; }

Property Value

IDocumentType

DocumentElement

Gets the root element of the document.

[DomName("documentElement")]
IElement DocumentElement { get; }

Property Value

IElement

DocumentUri

Gets the URI of the current document.

[DomName("documentURI")]
string DocumentUri { get; }

Property Value

string

Domain

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

[DomName("domain")]
string Domain { get; set; }

Property Value

string

Entities

Gets the associated entity provider.

IEntityProvider Entities { get; }

Property Value

IEntityProvider

Forms

Gets the forms in the document.

[DomName("forms")]
IHtmlCollection<IHtmlFormElement> Forms { get; }

Property Value

IHtmlCollection<IHtmlFormElement>

Head

Gets or sets the head element.

[DomName("head")]
IHtmlHeadElement? Head { get; }

Property Value

IHtmlHeadElement

Images

Gets the images in the document.

[DomName("images")]
IHtmlCollection<IHtmlImageElement> Images { get; }

Property Value

IHtmlCollection<IHtmlImageElement>

Implementation

Gets the DOM implementation associated with the current document.

[DomName("implementation")]
IImplementation Implementation { get; }

Property Value

IImplementation

ImportAncestor

Gets the import ancestor, if any.

IDocument? ImportAncestor { get; }

Property Value

IDocument

LastModified

Gets the date of the last modification.

[DomName("lastModified")]
string? LastModified { get; }

Property Value

string

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

[DomName("links")]
IHtmlCollection<IElement> Links { get; }

Property Value

IHtmlCollection<IElement>

Location

Gets the current location of the document.

[DomName("location")]
[DomPutForwards("href")]
ILocation Location { get; }

Property Value

ILocation

Origin

Gets the Unicode serialization of document's origin.

[DomName("origin")]
string? Origin { get; }

Property Value

string

Plugins

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

[DomName("embeds")]
[DomName("plugins")]
IHtmlCollection<IHtmlEmbedElement> Plugins { get; }

Property Value

IHtmlCollection<IHtmlEmbedElement>

ReadyState

Gets the current ready state of the document.

[DomLenientThis]
[DomName("readyState")]
DocumentReadyState ReadyState { get; }

Property Value

DocumentReadyState

Referrer

Gets the referer to that pointed to the current document.

[DomName("referrer")]
string? Referrer { get; }

Property Value

string

Scripts

Gets the scripts in the document.

[DomName("scripts")]
IHtmlCollection<IHtmlScriptElement> Scripts { get; }

Property Value

IHtmlCollection<IHtmlScriptElement>

Source

Gets the underlying source.

TextSource Source { get; }

Property Value

TextSource

StatusCode

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

HttpStatusCode StatusCode { get; }

Property Value

HttpStatusCode

Title

Gets or sets the title of the document.

[DomName("title")]
string? Title { get; set; }

Property Value

string

Url

Gets a string containing the URL of the current document.

[DomName("URL")]
string Url { get; }

Property Value

string

Methods

AddImportUrl(Uri)

Adds a Uri to the list of imported Uris.

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.

[DomName("adoptNode")]
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.

Close()

Finishes writing to a document.

[DomName("close")]
void Close()

CreateAttribute(string)

Creates an Attr of the given name.

[DomName("createAttribute")]
IAttr CreateAttribute(string name)

Parameters

name string

The name of the attribute.

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.

[DomName("createAttributeNS")]
IAttr CreateAttribute(string? namespaceUri, string name)

Parameters

namespaceUri string

The namespace URI of the attribute to create.

name string

The qualified name of the attribute to instantiate.

Returns

IAttr

A new Attr object.

CreateComment(string)

Creates a new comment node, and returns it.

[DomName("createComment")]
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.

[DomName("createDocumentFragment")]
IDocumentFragment CreateDocumentFragment()

Returns

IDocumentFragment

The new document fragment.

CreateElement(string)

Creates a new element with the given tag name.

[DomName("createElement")]
IElement CreateElement(string name)

Parameters

name string

A string that specifies the type of element to be created.

Returns

IElement

The created element object.

CreateElement(string?, string)

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

[DomName("createElementNS")]
IElement CreateElement(string? namespaceUri, string name)

Parameters

namespaceUri string

Specifies the namespace URI to associate with the element.

name string

A string that specifies the type of element to be created.

Returns

IElement

The created element.

CreateEvent(string)

Creates an event of the type specified.

[DomName("createEvent")]
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.

[DomName("createNodeIterator")]
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.

[DomName("createProcessingInstruction")]
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.

[DomName("createRange")]
IRange CreateRange()

Returns

IRange

The range.

CreateTextNode(string)

Creates a new text node and returns it.

[DomName("createTextNode")]
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.

[DomName("createTreeWalker")]
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.

ExecuteCommand(string, bool, string)

Executes a command with the provided id and the optional arguments.

[DomName("execCommand")]
bool ExecuteCommand(string commandId, bool showUserInterface = false, string value = "")

Parameters

commandId string

The id of the command to issue.

showUserInterface bool

Shall the UI be shown?

value string

The argument value of the command, if any.

Returns

bool

True if the command has been successfully executed, otherwise false.

GetCommandValue(string)

Gets the value of the document, range, or current selection, for the provided command.

[DomName("queryCommandValue")]
string? GetCommandValue(string commandId)

Parameters

commandId string

The id of the command to issue.

Returns

string

The modified value.

GetElementsByClassName(string)

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

[DomName("getElementsByClassName")]
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.

[DomName("getElementsByName")]
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.

[DomName("getElementsByTagName")]
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.

[DomName("getElementsByTagNameNS")]
IHtmlCollection<IElement> GetElementsByTagName(string? namespaceUri, string tagName)

Parameters

namespaceUri string

The namespace URI of elements to look for.

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.

HasFocus()

Checks if the document is currently focused.

[DomName("hasFocus")]
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.

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.

[DomName("importNode")]
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.

IsCommandEnabled(string)

Checks if the command with the provided id is enabled.

[DomName("queryCommandEnabled")]
bool IsCommandEnabled(string commandId)

Parameters

commandId string

The id of the command to check.

Returns

bool

True if the command exists and is enabled, otherwise false.

IsCommandExecuted(string)

Checks if the command with the provided id has already been executed for the current value.

[DomName("queryCommandState")]
bool IsCommandExecuted(string commandId)

Parameters

commandId string

The id of the command to check.

Returns

bool

True if the command has been executed, otherwise false.

IsCommandIndeterminate(string)

Checks if the command with the provided id is currently in an indeterminate state.

[DomName("queryCommandIndeterm")]
bool IsCommandIndeterminate(string commandId)

Parameters

commandId string

The id of the command to check.

Returns

bool

True if the command exists and is neither enabled nor disabled, otherwise false.

IsCommandSupported(string)

Checks if a command with the provided id exists and is supported in the current context.

[DomName("queryCommandSupported")]
bool IsCommandSupported(string commandId)

Parameters

commandId string

The id of the command to check.

Returns

bool

True if the command exists, otherwise false.

Load(string)

Loads the document content from the given url.

[DomName("load")]
void Load(string url)

Parameters

url string

The url that hosts the content.

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.

[DomName("open")]
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

Write(string)

Writes text to a document.

[DomName("write")]
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.

[DomName("writeln")]
void WriteLine(string content)

Parameters

content string

The text to be written on the document.

Events

ReadyStateChanged

Event triggered after the ready state changed.

[DomName("onreadystatechange")]
event DomEventHandler ReadyStateChanged

Event Type

DomEventHandler