Elements represent most of the "markup" and structure of the
document. They contain both the data for the element itself
(element name and attributes), and any contained nodes, including
document text (as children).
Elements may have Attributes associated with them; the API for this is
defined in Node, but the function is implemented here. In general, XML
applications should retrive Attributes as Nodes, since they may contain
entity references and hence be a fairly complex sub-tree. HTML users will
be dealing with simple string values, and convenience methods are provided
to work in terms of Strings.
ElementImpl does not support Namespaces. ElementNSImpl, which inherits from
Retrieve all the Attributes as a set. Note that this API is inherited
from Node rather than specified on Element; in fact only Elements will
ever have Attributes, but they want to allow folks to "blindly" operate
on the tree as a set of Nodes.
In "normal form" (as read from a source file), there will never be two
Text children in succession. But DOM users may create successive Text
nodes in the course of manipulating the document. Normalize walks the
sub-tree and merges adjacent Texts, as if the DOM had been written out
and read back in again. This simplifies implementation of higher-level
functions that may want to assume that the document is in standard form.
To normalize a Document, normalize its top-level Element child.
As of PR-DOM-Level-1-19980818, CDATA -- despite being a subclass of
Text -- is considered "markup" and will _not_ be merged either with
normal Text or with other CDATASections.
Remove the specified attribute/value pair. If the removed
Attribute has a default value, it is immediately replaced.
NOTE: Specifically removes THIS NODE -- not the node with this
name, nor the node with these contents. If the specific Attribute
object passed in is not stored in this Element, we throw a
DOMException. If you really want to remove an attribute by name,
DOMException(NOT_FOUND_ERR) - if oldattr is not an attribute of
DOMException(NO_MODIFICATION_ALLOWED_ERR) - if the node is
public void setAttribute(java.lang.String name,
Add a new name/value pair, or replace the value of the existing
attribute having that name.
Note: this method supports only the simplest kind of Attribute,
one whose value is a string contained in a single Text node.
If you want to assert a more complex value (which XML permits,
though HTML doesn't), see setAttributeNode().
The attribute is created with specified=true, meaning it's an
explicit value rather than inherited from the DTD as a default.
Again, setAttributeNode can be used to achieve other results.
Add a new attribute/value pair, or replace the value of the
existing attribute with that name.
This method allows you to add an Attribute that has already been
constructed, and hence avoids the limitations of the simple
setAttribute() call. It can handle attribute values that have
arbitrarily complex tree structure -- in particular, those which
had entity references mixed into their text.
namespaceURI - The namespace URI of the attribute to
localName - The local name of the attribute to retrieve.
String The Attr value as a string, or null
if that attribute
does not have a specified or default value.
public void setAttributeNS(java.lang.String namespaceURI,
Introduced in DOM Level 2.
Adds a new attribute.
If the given namespaceURI is null or an empty string and
predefined namespace "http://www.w3.org/XML/1998/namespace" [Namespaces].
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. This value is a simple string, it is not
parsed as it is being set. So any markup (such as syntax to be recognized as an
entity reference) is treated as literal text, and needs to be appropriately escaped by
the implementation when it is written out. In order to assign an attribute value that
contains entity references, the user must create an Attr node plus any Text and
EntityReference nodes, build the appropriate subtree, and use
setAttributeNodeNS or setAttributeNode to assign it as the value of an
namespaceURI - The namespace URI of the attribute to create
localName - The local name of the attribute to create or
value - The value to set in string form.
INVALID_CHARACTER_ERR: - Raised if the specified
name contains an invalid character.
NO_MODIFICATION_ALLOWED_ERR: - Raised if this
node is readonly.
NAMESPACE_ERR: - Raised if the qualifiedName
neither null nor an empty string nor
"http://www.w3.org/XML/1998/namespace", or if the
namespaceURI is neither null nor an empty string, or
if if the qualifiedName has a prefix different from
public void removeAttributeNS(java.lang.String namespaceURI,
Introduced in DOM Level 2.
Removes an attribute by local name and namespace URI. If the removed
attribute has a default value it is immediately replaced.
The replacing attribute has the same namespace URI and local name,
as well as the original prefix.