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
All
Gets a list of all elements in the document.
[DomName("all")]
IHtmlAllCollection All { get; }
Property Value
Anchors
Gets a list of all of the anchors in the document.
[DomName("anchors")]
IHtmlCollection<IHtmlAnchorElement> Anchors { get; }
Property Value
Body
Gets the body element.
[DomName("body")]
IHtmlElement? Body { get; set; }
Property Value
CharacterSet
Gets the character encoding of the current document.
[DomName("characterSet")]
string CharacterSet { get; }
Property Value
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
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
ContentType
Gets the Content-Type from the MIME Header of the current document.
[DomName("contentType")]
string ContentType { get; }
Property Value
Context
Gets the browsing context to use.
IBrowsingContext Context { get; }
Property Value
Cookie
Gets or sets the document cookie.
[DomName("cookie")]
string Cookie { get; set; }
Property Value
CurrentScript
Gets the script element which is currently being processed.
[DomName("currentScript")]
IHtmlScriptElement? CurrentScript { get; }
Property Value
DefaultView
Gets the window object associated with the document or null if none available.
[DomName("defaultView")]
IWindow? DefaultView { get; }
Property Value
DesignMode
Gets or sets whether the entire document is editable.
[DomName("designMode")]
string DesignMode { get; set; }
Property Value
Direction
Gets or sets the value of the dir attribute.
[DomName("dir")]
string? Direction { get; set; }
Property Value
Doctype
Gets the document type.
[DomName("doctype")]
IDocumentType Doctype { get; }
Property Value
DocumentElement
Gets the root element of the document.
[DomName("documentElement")]
IElement DocumentElement { get; }
Property Value
DocumentUri
Gets the URI of the current document.
[DomName("documentURI")]
string DocumentUri { get; }
Property Value
Domain
Gets or sets the domain portion of the origin of the current document.
[DomName("domain")]
string Domain { get; set; }
Property Value
Entities
Gets the associated entity provider.
IEntityProvider Entities { get; }
Property Value
Forms
Gets the forms in the document.
[DomName("forms")]
IHtmlCollection<IHtmlFormElement> Forms { get; }
Property Value
Head
Gets or sets the head element.
[DomName("head")]
IHtmlHeadElement? Head { get; }
Property Value
Images
Gets the images in the document.
[DomName("images")]
IHtmlCollection<IHtmlImageElement> Images { get; }
Property Value
Implementation
Gets the DOM implementation associated with the current document.
[DomName("implementation")]
IImplementation Implementation { get; }
Property Value
ImportAncestor
Gets the import ancestor, if any.
IDocument? ImportAncestor { get; }
Property Value
LastModified
Gets the date of the last modification.
[DomName("lastModified")]
string? LastModified { get; }
Property Value
Links
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
Location
Gets the current location of the document.
[DomName("location")]
[DomPutForwards("href")]
ILocation Location { get; }
Property Value
Origin
Gets the Unicode serialization of document's origin.
[DomName("origin")]
string? Origin { get; }
Property Value
Plugins
Gets a list of the embed elements within the current document.
[DomName("embeds")]
[DomName("plugins")]
IHtmlCollection<IHtmlEmbedElement> Plugins { get; }
Property Value
ReadyState
Gets the current ready state of the document.
[DomLenientThis]
[DomName("readyState")]
DocumentReadyState ReadyState { get; }
Property Value
Referrer
Gets the referer to that pointed to the current document.
[DomName("referrer")]
string? Referrer { get; }
Property Value
Scripts
Gets the scripts in the document.
[DomName("scripts")]
IHtmlCollection<IHtmlScriptElement> Scripts { get; }
Property Value
Source
Gets the underlying source.
TextSource Source { get; }
Property Value
StatusCode
Gets the status code of the server's response, if any.
HttpStatusCode StatusCode { get; }
Property Value
Title
Gets or sets the title of the document.
[DomName("title")]
string? Title { get; set; }
Property Value
Url
Gets a string containing the URL of the current document.
[DomName("URL")]
string Url { get; }
Property Value
Methods
AddImportUrl(Uri)
Adds a Uri to the list of imported Uris.
bool AddImportUrl(Uri uri)
Parameters
uri
UriThe 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
INodeThe 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
stringThe 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
stringThe namespace URI of the attribute to create.
name
stringThe 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
stringA 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
stringA 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
stringSpecifies the namespace URI to associate with the element.
name
stringA 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
stringRepresents 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
INodeThe root node at which to begin the NodeIterator's traversal.
settings
FilterSettingsIndicates which nodes to iterate over.
filter
NodeFilterAn 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
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
stringA 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
INodeIs the root Node of this TreeWalker traversal.
settings
FilterSettingsIndicates which nodes to iterate over.
filter
NodeFilterAn 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
stringThe id of the command to issue.
showUserInterface
boolShall the UI be shown?
value
stringThe 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
stringThe 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
stringA 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
stringThe 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
stringA 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
stringThe namespace URI of elements to look for.
tagName
stringEither 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
UriThe 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
INodeThe node from another document to be imported.
deep
boolOptional 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
stringThe 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
stringThe 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
stringThe 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
stringThe 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
stringThe 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
Returns
Write(string)
Writes text to a document.
[DomName("write")]
void Write(string content)
Parameters
content
stringThe 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
stringThe text to be written on the document.
Events
ReadyStateChanged
Event triggered after the ready state changed.
[DomName("onreadystatechange")]
event DomEventHandler ReadyStateChanged