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
IBrowsingContextsource
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
All
Gets a list of all elements in the document.
public IHtmlAllCollection All { get; }
Property Value
Anchors
Gets a list of all of the anchors in the document.
public IHtmlCollection<IHtmlAnchorElement> Anchors { get; }
Property Value
Body
Gets the body element.
public IHtmlElement? Body { get; set; }
Property Value
CharacterSet
Gets the character encoding of the current document.
public string CharacterSet { get; }
Property Value
ChildElementCount
Gets the number of child elements.
public int ChildElementCount { get; }
Property Value
Children
Gets the child elements.
public IHtmlCollection<IElement> Children { get; }
Property Value
Commands
Gets a list of the commands (menu item, button, and link elements) within the current document.
public 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).
public string CompatMode { get; }
Property Value
ContentType
Gets the Content-Type from the MIME Header of the current document.
public string ContentType { get; protected set; }
Property Value
Context
Gets the browsing context to use.
public IBrowsingContext Context { get; }
Property Value
Cookie
Gets or sets the document cookie.
public string Cookie { get; set; }
Property Value
CurrentScript
Gets the script element which is currently being processed.
public IHtmlScriptElement? CurrentScript { get; }
Property Value
DefaultView
Gets the window object associated with the document or null if none available.
public IWindow DefaultView { get; }
Property Value
DesignMode
Gets or sets whether the entire document is editable.
public string DesignMode { get; set; }
Property Value
Direction
Gets or sets the value of the dir attribute.
public string? Direction { get; set; }
Property Value
Doctype
Gets the document type.
public IDocumentType Doctype { get; }
Property Value
DocumentElement
Gets the root element of the document.
public abstract IElement DocumentElement { get; }
Property Value
DocumentUri
Gets the URI of the current document.
public string DocumentUri { get; protected set; }
Property Value
DocumentUrl
public Url DocumentUrl { get; }
Property Value
Domain
Gets or sets the domain portion of the origin of the current document.
public string Domain { get; set; }
Property Value
Entities
Gets the associated entity provider.
public abstract IEntityProvider Entities { get; }
Property Value
FirstElementChild
Gets the first child element of this element.
public IElement? FirstElementChild { get; }
Property Value
Forms
Gets the forms in the document.
public IHtmlCollection<IHtmlFormElement> Forms { get; }
Property Value
Head
Gets or sets the head element.
public IHtmlHeadElement? Head { get; }
Property Value
Images
Gets the images in the document.
public IHtmlCollection<IHtmlImageElement> Images { get; }
Property Value
Implementation
Gets the DOM implementation associated with the current document.
public IImplementation Implementation { get; }
Property Value
ImportAncestor
Gets the import ancestor, if any.
public IDocument? ImportAncestor { get; }
Property Value
IsAsync
public bool IsAsync { get; }
Property Value
IsLoading
public bool IsLoading { get; }
Property Value
IsReady
public bool IsReady { get; }
Property Value
LastElementChild
Gets the last child element of this element.
public IElement? LastElementChild { get; }
Property Value
LastModified
Gets the date of the last modification.
public string? LastModified { get; protected set; }
Property Value
LastStyleSheetSet
Gets the last stylesheet set.
public string? LastStyleSheetSet { get; }
Property Value
Links
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
Location
Gets the current location of the document.
public ILocation Location { get; }
Property Value
Loop
public IEventLoop? Loop { get; }
Property Value
Origin
Gets the Unicode serialization of document's origin.
public string? Origin { get; }
Property Value
Plugins
Gets a list of the embed elements within the current document.
public IHtmlCollection<IHtmlEmbedElement> Plugins { get; }
Property Value
PreferredStyleSheetSet
Gets the preferred stylesheet set.
public string? PreferredStyleSheetSet { get; }
Property Value
ReadyState
Gets the current ready state of the document.
public DocumentReadyState ReadyState { get; protected set; }
Property Value
Referrer
Gets the referer to that pointed to the current document.
public string Referrer { get; protected set; }
Property Value
Scripts
Gets the scripts in the document.
public IHtmlCollection<IHtmlScriptElement> Scripts { get; }
Property Value
SelectedStyleSheetSet
Gets or sets the selected set of stylesheets.
public string? SelectedStyleSheetSet { get; set; }
Property Value
Source
Gets the underlying source.
public TextSource Source { get; }
Property Value
StatusCode
Gets the status code of the server's response, if any.
public HttpStatusCode StatusCode { get; }
Property Value
StyleSheetSets
Gets a live list of all of the currently-available style sheet sets.
public IStringList StyleSheetSets { get; }
Property Value
StyleSheets
Gets a list of stylesheet objects for stylesheets explicitly linked into or embedded in a document.
public IStyleSheetList StyleSheets { get; }
Property Value
Title
Gets or sets the title of the document.
public string? Title { get; set; }
Property Value
Url
Gets a string containing the URL of the current document.
public string Url { get; }
Property Value
Methods
AddImportUrl(Uri)
Adds a Uri to the list of imported Uris.
public 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.
public 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.
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
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
Returns
- IAttr
A new Attr object.
CreateComment(string)
Creates a new comment node, and returns it.
public 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.
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
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
stringThe name of the new element.
prefix
stringThe optional prefix to use.
flags
NodeFlagsThe 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
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.
public 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.
public IProcessingInstruction CreateProcessingInstruction(string target, string data)
Parameters
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
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.
public 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.
DelayLoad(Task?)
Waits for the given task before raising the load event.
public void DelayLoad(Task? task)
Parameters
task
TaskThe 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
stringThe 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
stringA 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
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.
public 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.
public 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.
public IHtmlCollection<IElement> GetElementsByTagName(string? namespaceURI, string tagName)
Parameters
namespaceURI
stringtagName
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.
GetTitle()
protected virtual string GetTitle()
Returns
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
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.
public 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.
Load(string)
Loads the document content from the given url.
public void Load(string url)
Parameters
url
stringThe url that hosts the content.
LocateNamespace(string)
protected override sealed string? LocateNamespace(string prefix)
Parameters
prefix
string
Returns
LocatePrefix(string)
protected override sealed string? LocatePrefix(string namespaceUri)
Parameters
namespaceUri
string
Returns
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
Returns
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
stringThe 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
stringThe 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
IResponseThe received response.
contentType
MimeTypeThe content-type.
importAncestor
IDocumentThe ancestor, if any.
Write(string)
Writes text to a document.
public void Write(string content)
Parameters
content
stringThe text to be written on the document.
WriteLine(string)
Writes a line of text to a document.
public void WriteLine(string content)
Parameters
content
stringThe text to be written on the document.
Events
Aborted
Event triggered after aborting.
public event DomEventHandler Aborted
Event Type
Blurred
Event triggered after losing focus.
public event DomEventHandler Blurred
Event Type
CanPlay
Event triggered when the media can be played.
public event DomEventHandler CanPlay
Event Type
CanPlayThrough
Event triggered when the media can be fully played.
public event DomEventHandler CanPlayThrough
Event Type
Cancelled
Event triggered after cancelling.
public event DomEventHandler Cancelled
Event Type
Changed
Event triggered after the value changed.
public event DomEventHandler Changed
Event Type
Clicked
Event triggered after being clicked.
public event DomEventHandler Clicked
Event Type
CueChanged
Event triggered after changing the cue.
public event DomEventHandler CueChanged
Event Type
DoubleClick
Event triggered after performing a double click.
public event DomEventHandler DoubleClick
Event Type
Drag
Event triggered after starting to be dragged.
public event DomEventHandler Drag
Event Type
DragEnd
Event triggered after being dragged.
public event DomEventHandler DragEnd
Event Type
DragEnter
Event triggered after entering in dragging mode.
public event DomEventHandler DragEnter
Event Type
DragExit
Event triggered after exiting the dragging mode.
public event DomEventHandler DragExit
Event Type
DragLeave
Event triggered after leaving in dragging mode.
public event DomEventHandler DragLeave
Event Type
DragOver
Event triggered after hovering in dragging mode.
public event DomEventHandler DragOver
Event Type
DragStart
Event triggered after starting to drag.
public event DomEventHandler DragStart
Event Type
Dropped
Event triggered after dropping.
public event DomEventHandler Dropped
Event Type
DurationChanged
Event triggered when the media cursor changed.
public event DomEventHandler DurationChanged
Event Type
Emptied
Event triggered after being emptied.
public event DomEventHandler Emptied
Event Type
Ended
Event triggered after the media ended.
public event DomEventHandler Ended
Event Type
Error
Event triggered after an error occurred.
public event DomEventHandler Error
Event Type
Focused
Event triggered after receiving focus.
public event DomEventHandler Focused
Event Type
Input
Event triggered after input has happend.
public event DomEventHandler Input
Event Type
Invalid
Event triggered after validation failed.
public event DomEventHandler Invalid
Event Type
KeyDown
Event triggered after key down.
public event DomEventHandler KeyDown
Event Type
KeyPress
Event triggered after key press.
public event DomEventHandler KeyPress
Event Type
KeyUp
Event triggered after key up.
public event DomEventHandler KeyUp
Event Type
Loaded
Event triggered after the content has been fully loaded.
public event DomEventHandler Loaded
Event Type
LoadedData
Event triggered after the data has been loaded.
public event DomEventHandler LoadedData
Event Type
LoadedMetadata
Event triggered after the meta data has been received.
public event DomEventHandler LoadedMetadata
Event Type
Loading
Event triggered when loading begins.
public event DomEventHandler Loading
Event Type
MouseDown
Event triggered after mouse down.
public event DomEventHandler MouseDown
Event Type
MouseEnter
Event triggered after mouse enter.
public event DomEventHandler MouseEnter
Event Type
MouseLeave
Event triggered after mouse leave.
public event DomEventHandler MouseLeave
Event Type
MouseMove
Event triggered after mouse move.
public event DomEventHandler MouseMove
Event Type
MouseOut
Event triggered after mouse out.
public event DomEventHandler MouseOut
Event Type
MouseOver
Event triggered after mouse over.
public event DomEventHandler MouseOver
Event Type
MouseUp
Event triggered after mouse up.
public event DomEventHandler MouseUp
Event Type
MouseWheel
Event triggered after mouse wheel.
public event DomEventHandler MouseWheel
Event Type
Paused
Event triggered after the media paused.
public event DomEventHandler Paused
Event Type
Played
Event triggered after the media started.
public event DomEventHandler Played
Event Type
Playing
Event triggered before the media started.
public event DomEventHandler Playing
Event Type
Progress
Event triggered after progress.
public event DomEventHandler Progress
Event Type
RateChanged
Event triggered after the rate changed.
public event DomEventHandler RateChanged
Event Type
ReadyStateChanged
Event triggered after the ready state changed.
public event DomEventHandler ReadyStateChanged
Event Type
Resetted
Event triggered after resetting the form.
public event DomEventHandler Resetted
Event Type
Resized
Event triggered after resizing the window.
public event DomEventHandler Resized
Event Type
Scrolled
Event triggered after scrolling has happened.
public event DomEventHandler Scrolled
Event Type
Seeked
Event triggered after seeking in the media stream.
public event DomEventHandler Seeked
Event Type
Seeking
Event triggered before seeking in the media stream.
public event DomEventHandler Seeking
Event Type
Selected
Event triggered after selected the element.
public event DomEventHandler Selected
Event Type
Shown
Event triggered after being shown.
public event DomEventHandler Shown
Event Type
Stalled
Event triggered after being stalled.
public event DomEventHandler Stalled
Event Type
Submitted
Event triggered after the form has been submitted.
public event DomEventHandler Submitted
Event Type
Suspended
Event triggered after suspending.
public event DomEventHandler Suspended
Event Type
TimeUpdated
Event triggered after the time updated.
public event DomEventHandler TimeUpdated
Event Type
Toggled
Event triggered after being toggled.
public event DomEventHandler Toggled
Event Type
VolumeChanged
Event triggered after the volume changed.
public event DomEventHandler VolumeChanged
Event Type
Waiting
Event triggered when waiting for input.
public event DomEventHandler Waiting