L'interface Element représente un élément dans un document HTML ou XML.

<?xml version="1.0" encoding="UTF-16"?>
<element>
   <autreElement attribut="valeur">
      Texte...
   </autreElement>
</element>

Les éléments peuvent être associés à des attributs. Ils peuvent contenir d'autres éléments ou/et du texte.

En HTML, les éléments sont normalisés par différentes recommandations du W3C. Les documents HTML doivent donc suivre des définitions de type de document établies.

<?xml version="1.0" encoding="UTF-16"?>
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title>Titre...</title>
   </head>
   <body>
      <p>Texte...</p>
   </body>
</html>

En XML, les éléments doivent être bien formés et respecter les règles énoncées dans la définition de type de document (DTD) ou dans les divers schémas W3C, Relax NG ou autres.

L'interface Element étend l'interface Node. Ainsi, les champs et attributs de l'interface Node sont tous disponibles à partir d'un élément.

Champ
Description
Les champs hérités de l'interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE,
DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE,
DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS,
DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING,
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC,
DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE,
ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE,
PROCESSING_INSTRUCTION_NODE, TEXT_NODE
Méthode
Description
String getAttribute(String nom)
récupère la valeur d'un attribut correspondant au nom spécifié.
Attr getAttributeNode(String nom)
récupère l'attribut correspondant au nom spécifié.
Attr getAttributeNodeNS(String URIEspaceNoms, String nomLocal)
récupère l'attribut correspondant au nom spécifié et situé dans l'espace de noms indiqué.
String getAttributeNS(String URIEspaceNoms, String nomLocal)
récupère la valeur d'un attribut correspondant au nom spécifié et situé dans l'espace de noms indiqué.
NodeList getElementsByTagName(String nom)
retourne une liste d'éléments possèdant le nom passé en argument. L'ordre du document est respecté.
NodeList getElementsByTagNameNS(String URIEspaceNoms, String nomLocal)
retourne une liste d'éléments possèdant le nom passé en argument et situés dans l'espace de noms fourni. L'ordre du document est respecté.
TypeInfo getSchemaTypeInfo()
retourne le type associé à l'élément.
String getTagName()
retourne le nom de l'élément.
boolean hasAttribute(String nom)
indique si l'élément possède des attributs.
boolean hasAttributeNS(String URIEspaceNoms, String nomLocal)
indique si l'élément possède des attributs correspondant au nomlocal indiqué et situés dans l'espace de noms.
void removeAttribute(String nom)
supprime l'attribut correspondant au nom passé en argument.
Attr removeAttributeNode(Attr oldAttr)
supprime l'attribut correspondant à l'objet Attr passé en argument.
void removeAttributeNS(String URIEspaceNoms, String nomLocal)
supprime l'attribut correspondant au nom local passé en argument et situé dans l'espace de noms requis.
void setAttribute(String nom, String valeur)
ajoute un nouvel attribut dans l'élément.
Attr setAttributeNode(Attr newAttr)
ajoute un nouveau noeud Attr dans l'élément.
Attr setAttributeNodeNS(Attr newAttr)
ajoute un nouveau noeud Attr situé dans un espace de noms, dans l'élément.
void setAttributeNS(String URIEspaceNoms, String nomQualifie, String valeur)
ajoute un nouvel attribut situé dans un espace de noms, dans l'élément.
void setIdAttribute(String nom, boolean isId)
ajoute un attribut id au sein de l'élément. Si le second argument est égal à true, alors cet attribut sera déclaré comme un identificateur ID.
void setIdAttributeNode(Attr idAttr, boolean isId)
ajoute un noeud attribut id au sein de l'élément. Si le second argument est égal à true, alors cet attribut sera déclaré comme un identificateur ID.
void setIdAttributeNS(String URIEspaceNoms, String nomLocal, boolean isId)
ajoute un noeud attribut identificateur situé dans un espace de noms, au sein de l'élément. Si le second argument est égal à true, alors cet attribut sera déclaré comme un identificateur ID.
Les méthodes héritées de l'interface org.w3c.dom.Node
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI,
getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName,
getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue,
getOwnerDocument, getParentNode, getPrefix, getPreviousSibling,
getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore,
isDefaultNamespace, isEqualNode, isSameNode, isSupported,
lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild,
setNodeValue, setPrefix, setTextContent, setUserData