Class Element
Namespace: Aspose.Html.Dom
Assembly: Aspose.HTML.dll (25.2.0)
The Element interface represents an element in an HTML or XML document.
[ComVisible(true)]
[DOMName("Element")]
[DOMObject]
public class Element : Node, INotifyPropertyChanged, IEventTarget, IDisposable, IXPathNSResolver, IParentNode, IElementTraversal, IChildNode
Inheritance
object ← DOMObject ← EventTarget ← Node ← Element
Derived
Implements
INotifyPropertyChanged, IEventTarget, IDisposable, IXPathNSResolver, IParentNode, IElementTraversal, IChildNode
Inherited Members
Node.ELEMENT_NODE, Node.ATTRIBUTE_NODE, Node.TEXT_NODE, Node.CDATA_SECTION_NODE, Node.ENTITY_REFERENCE_NODE, Node.ENTITY_NODE, Node.PROCESSING_INSTRUCTION_NODE, Node.COMMENT_NODE, Node.DOCUMENT_NODE, Node.DOCUMENT_TYPE_NODE, Node.DOCUMENT_FRAGMENT_NODE, Node.NOTATION_NODE, Node.HasChildNodes(), Node.Normalize(), Node.CloneNode(), Node.CloneNode(bool), Node.IsEqualNode(Node), Node.IsSameNode(Node), Node.LookupPrefix(string), Node.LookupNamespaceURI(string), Node.IsDefaultNamespace(string), Node.InsertBefore(Node, Node), Node.ReplaceChild(Node, Node), Node.RemoveChild(Node), Node.AppendChild(Node), Node.Dispose(bool), Node.ToString(), Node.NodeType, Node.LocalName, Node.NamespaceURI, Node.Prefix, Node.NodeName, Node.BaseURI, Node.OwnerDocument, Node.ParentNode, Node.ParentElement, Node.ChildNodes, Node.FirstChild, Node.LastChild, Node.PreviousSibling, Node.NextSibling, Node.NodeValue, Node.TextContent, EventTarget.AddEventListener(string, DOMEventHandler, bool), EventTarget.AddEventListener(string, IEventListener), EventTarget.AddEventListener(string, IEventListener, bool), EventTarget.RemoveEventListener(string, DOMEventHandler, bool), EventTarget.RemoveEventListener(string, IEventListener), EventTarget.RemoveEventListener(string, IEventListener, bool), EventTarget.DispatchEvent(Event), EventTarget.Dispose(), EventTarget.Dispose(bool), DOMObject.GetPlatformType(), object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Constructors
Element(QualifiedName, Document)
Initializes a new instance of the Aspose.Html.Dom.Element class. Don’t call this constructor directly, use Aspose.Html.Dom.Document.CreateElement(System.String) or Aspose.Html.Dom.Document.CreateElementNS(System.String,System.String).
public Element(QualifiedName qualifiedName, Document document)
Parameters
qualifiedName
QualifiedName
The qualified name.
document
Document
The associated document.
Properties
Attributes
A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
[DOMName("attributes")]
public NamedNodeMap Attributes { get; }
Property Value
ChildElementCount
Returns the current number of element nodes that are children of this element. 0 if this element has no child nodes that are of nodeType 1.
public int ChildElementCount { get; }
Property Value
Children
Returns the child elements of current element.
public HTMLCollection Children { get; }
Property Value
ClassList
Returns a live DOMTokenList which contains tokens received from parsing the “class” attribute.
[DOMName("classList")]
public DOMTokenList ClassList { get; }
Property Value
ClassName
The class attribute of the element. This attribute has been renamed due to conflicts with the “class” keyword exposed by many languages. See the class attribute definition in HTML 4.01.
[DOMName("className")]
public string ClassName { get; set; }
Property Value
FirstElementChild
Returns the first child element node of this element. null if this element has no child elements.
public Element FirstElementChild { get; }
Property Value
Id
The element’s identifier. See the id attribute definition in HTML 4.01.
[DOMName("id")]
public string Id { get; set; }
Property Value
InnerHTML
Returns a fragment of HTML or XML that represents the element’s contents. Can be set, to replace the contents of the element with nodes parsed from the given string.
[DOMName("innerHTML")]
public string InnerHTML { get; set; }
Property Value
LastElementChild
Returns the last child element node of this element. null if this element has no child elements.
public Element LastElementChild { get; }
Property Value
LocalName
Returns the local part of the qualified name of this node. For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as Document.createElement(), this is always null.
public override string LocalName { get; }
Property Value
NamespaceURI
The namespace URI of this node, or null if it is unspecified.
[DOMNullable]
[DOMName("namespaceURI")]
public override string NamespaceURI { get; }
Property Value
NextElementSibling
Returns the next sibling element node of this element. null if this element has no element sibling nodes that come after this one in the document tree.
public Element NextElementSibling { get; }
Property Value
NodeName
The name of this node, depending on its type.
public override string NodeName { get; }
Property Value
NodeType
A code representing the type of the underlying object.
public override ushort NodeType { get; }
Property Value
OuterHTML
Returns a fragment of HTML or XML that represents the element and its contents. Can be set, to replace the element with nodes parsed from the given string.
[DOMName("outerHTML")]
public string OuterHTML { get; set; }
Property Value
Prefix
The namespace prefix of this node, or null if it is unspecified. When it is defined to be null, setting it has no effect
[DOMNullable]
[DOMName("prefix")]
public override string Prefix { get; }
Property Value
PreviousElementSibling
Returns the previous sibling element node of this element. null if this element has no element sibling nodes that come before this one in the document tree.
public Element PreviousElementSibling { get; }
Property Value
ShadowRoot
Returns shadowRoot stored on this element or null if it’s closed.
[DOMName("shadowRoot")]
public ShadowRoot ShadowRoot { get; }
Property Value
TagName
The name of the element.
[DOMName("tagName")]
public string TagName { get; }
Property Value
TextContent
This attribute returns the text content of this node and its descendants. When it is defined to be null, setting it has no effect. On setting, any possible children this node may have are removed and, if it the new string is not empty or null, replaced by a single Text node containing the string this attribute is set to.
public override string TextContent { get; set; }
Property Value
Methods
AttachShadow(ShadowRootMode)
Creates shadow root and attaches it to current element.
[DOMName("attachShadow")]
public ShadowRoot AttachShadow(ShadowRootMode mode)
Parameters
mode
ShadowRootMode
Mode in which shadow root will be created.
Returns
Created Aspose.Html.Dom.ShadowRoot.
Exceptions
NotSupportedError: Element does not support shadow tree.
InvalidStateError: Element already has shadow tree.
Dispose(bool)
Releases unmanaged and - optionally - managed resources.
protected override void Dispose(bool disposing)
Parameters
disposing
bool
true
to release both managed and unmanaged resources; false
to release only unmanaged resources.
GetAttribute(string)
Retrieves an attribute value by name.
[DOMName("getAttribute")]
[DOMNullable]
public string GetAttribute(string qualifiedName)
Parameters
qualifiedName
string
The name of the attribute to retrieve.
Returns
Returns attribute value
GetAttributeNS(string, string)
Retrieves an attribute value by local name and namespace URI.
[DOMNullable]
[DOMName("getAttributeNS")]
public string GetAttributeNS(string namespaceURI, string localName)
Parameters
namespaceURI
string
The namespace URI.
localName
string
Name of the local.
Returns
Returns attribute
GetAttributeNames()
Returns the attribute names of the element as an Array of strings. If the element has no attributes it returns an empty array.
[DOMName("getAttributeNames")]
public string[] GetAttributeNames()
Returns
string[]
Array of strings represents attribute names.
GetAttributeNode(string)
Retrieves an attribute node by name.
[DOMName("getAttributeNode")]
public Attr GetAttributeNode(string qualifiedName)
Parameters
qualifiedName
string
The attribute name.
Returns
Returns attribute value
GetAttributeNodeNS(string, string)
Retrieves an Attr node by local name and namespace URI.
[DOMName("getAttributeNodeNS")]
public Attr GetAttributeNodeNS(string namespaceURI, string localName)
Parameters
namespaceURI
string
The namespace URI.
localName
string
Name of the local.
Returns
Returns attribute
GetElementsByClassName(string)
Returns a live NodeList object containing all the elements in the document that have all the classes specified in argument. http://www.w3.org/TR/dom/
[DOMName("getElementsByClassName")]
public HTMLCollection GetElementsByClassName(string classNames)
Parameters
classNames
string
The string string that contains an unordered set of unique space-separated tokens representing classes (class names)
Returns
The Aspose.Html.Dom.Element.
GetElementsByTagName(string)
Returns a NodeList of all descendant Elements with a given tag name, in document order.
[DOMName("getElementsByTagName")]
public HTMLCollection GetElementsByTagName(string name)
Parameters
name
string
The tag name.
Returns
Returns attribute
GetElementsByTagNameNS(string, string)
Returns a NodeList of all the descendant Elements with a given local name and namespace URI in document order.
[DOMName("getElementsByTagNameNS")]
public HTMLCollection GetElementsByTagNameNS(string namespaceURI, string localName)
Parameters
namespaceURI
string
The namespace URI.
localName
string
Name of the local.
Returns
Returns elements
HasAttribute(string)
Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.
[DOMName("hasAttribute")]
public bool HasAttribute(string qualifiedName)
Parameters
qualifiedName
string
The attribute name.
Returns
true
if the specified name has attribute; otherwise, false
.
HasAttributeNS(string, string)
Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise.
[DOMName("hasAttributeNS")]
public bool HasAttributeNS(string namespaceURI, string localName)
Parameters
namespaceURI
string
The namespace URI.
localName
string
Name of the local.
Returns
true
if [has attribute NS] [the specified namespace URI]; otherwise, false
.
HasAttributes()
Returns whether this node (if it is an element) has any attributes
[DOMName("hasAttributes")]
public bool HasAttributes()
Returns
boolean true
if this node has any attributes, false
otherwise.
QuerySelector(string)
Returns the first Element in document, which match selector
public Element QuerySelector(string selector)
Parameters
selector
string
The selector.
Returns
The matched element
QuerySelectorAll(string)
Returns a NodeList of all the Elements in document, which match selector
public NodeList QuerySelectorAll(string selector)
Parameters
selector
string
The selector
Returns
Aspose.Html.Collections.HTMLCollection
Remove()
Removes this instance.
public void Remove()
RemoveAttribute(string)
Removes an attribute by name.
[DOMName("removeAttribute")]
public void RemoveAttribute(string qualifiedName)
Parameters
qualifiedName
string
The attribute name.
RemoveAttributeNS(string, string)
Removes an attribute by local name and namespace URI.
[DOMName("removeAttributeNS")]
public void RemoveAttributeNS(string namespaceURI, string localName)
Parameters
namespaceURI
string
The namespace URI.
localName
string
Name of the local.
RemoveAttributeNode(Attr)
Removes the specified attribute node.
[DOMName("removeAttributeNode")]
public Attr RemoveAttributeNode(Attr oldAttr)
Parameters
oldAttr
Attr
The old attr.
Returns
Returns attribute
SetAttribute(string, string)
Adds a new attribute. If an attribute with that name is already present in the element, its value is changed to be that of the value parameter
[DOMName("setAttribute")]
public void SetAttribute(string qualifiedName, string value)
Parameters
qualifiedName
string
The attribute name.
value
string
The value.
SetAttributeNS(string, string, string)
Adds a new attribute. If an attribute with the same local name and namespace URI is already present on the element, its prefix is changed to be the prefix part of the qualifiedName, and its value is changed to be the value parameter.
[DOMName("setAttributeNS")]
public void SetAttributeNS(string namespaceURI, string qualifiedName, string value)
Parameters
namespaceURI
string
The namespace URI.
qualifiedName
string
Name of the qualified.
value
string
The value.
SetAttributeNode(Attr)
Adds a new attribute node. If an attribute with that name (nodeName) is already present in the element, it is replaced by the new one.
[DOMName("setAttributeNode")]
public Attr SetAttributeNode(Attr newAttr)
Parameters
newAttr
Attr
The new attr.
Returns
Returns attribute
SetAttributeNodeNS(Attr)
Adds a new attribute. If an attribute with that local name and that namespace URI is already present in the element, it is replaced by the new one.
[DOMName("setAttributeNodeNS")]
public Attr SetAttributeNodeNS(Attr newAttr)
Parameters
newAttr
Attr
The new attr.
Returns
Returns attribute
ToggleAttribute(string)
If force is not given, “toggles” qualifiedName, removing it if it is present and adding it if it is not present. If force is true, adds qualifiedName. If force is false, removes qualifiedName.
[DOMName("toggleAttribute")]
public bool ToggleAttribute(string qualifiedName)
Parameters
qualifiedName
string
The attribute QualifiedName.
Returns
Returns true if qualifiedName is now present; otherwise false.
ToggleAttribute(string, bool)
If force is not given, “toggles” qualifiedName, removing it if it is present and adding it if it is not present. If force is true, adds qualifiedName. If force is false, removes qualifiedName.
[DOMName("toggleAttribute")]
public bool ToggleAttribute(string qualifiedName, bool force)
Parameters
qualifiedName
string
The attribute QualifiedName.
force
bool
The force option to toggle attribute.
Returns
Returns true if qualifiedName is now present; otherwise false.