public class DOMElement extends DefaultElement implements Element
DOMAttribute
implements an XML element which
supports the W3C DOM API.
Modifier and Type | Field and Description |
---|---|
private static DocumentFactory |
DOCUMENT_FACTORY
The
DocumentFactory instance used by default |
EMPTY_ITERATOR, EMPTY_LIST, USE_STRINGVALUE_SEPARATOR, VERBOSE_TOSTRING
DEFAULT_CONTENT_LIST_SIZE, outputFormat
NODE_TYPE_NAMES
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
ANY_NODE, ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, MAX_NODE_TYPE, NAMESPACE_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE, UNKNOWN_NODE
Constructor and Description |
---|
DOMElement(QName qname) |
DOMElement(QName qname,
int attributeCount) |
DOMElement(String name) |
DOMElement(String name,
Namespace namespace) |
Modifier and Type | Method and Description |
---|---|
Node |
appendChild(Node newChild)
Adds the node
newChild to the end of the list of children
of this node. |
protected Attribute |
attribute(Attr attr) |
protected Attribute |
attribute(String namespaceURI,
String localName) |
Node |
cloneNode(boolean deep)
Returns a duplicate of this node, i.e., serves as a generic copy
constructor for nodes.
|
protected Attribute |
createAttribute(Attr newAttr) |
String |
getAttribute(String name)
Retrieves an attribute value by name.
|
Attr |
getAttributeNode(String name)
Retrieves an attribute node by name.
|
Attr |
getAttributeNodeNS(String namespaceURI,
String localName)
Retrieves an
Attr node by local name and namespace URI. |
String |
getAttributeNS(String namespaceURI,
String localName)
Retrieves an attribute value by local name and namespace URI.
|
NamedNodeMap |
getAttributes()
A
NamedNodeMap containing the attributes of this node (if
it is an Element ) or null otherwise. |
NodeList |
getChildNodes()
A
NodeList that contains all children of this node. |
protected DocumentFactory |
getDocumentFactory() |
NodeList |
getElementsByTagName(String name)
Returns a
NodeList of all descendant Elements
with a given tag name, in the order in which they are encountered in
a preorder traversal of this Element tree. |
NodeList |
getElementsByTagNameNS(String namespaceURI,
String localName)
Returns a
NodeList of all the descendant
Elements with a given local name and namespace URI in
the order in which they are encountered in a preorder traversal of
this Element tree. |
Node |
getFirstChild()
The first child of this node.
|
Node |
getLastChild()
The last child of this node.
|
String |
getLocalName()
Returns the local part of the qualified name of this node.
|
String |
getNamespaceURI()
Returns the URI mapped to the namespace of this element
if one exists otherwise an empty
String is returned. |
Node |
getNextSibling()
The node immediately following this node.
|
String |
getNodeName()
The name of this node, depending on its type; see the table above.
|
String |
getNodeValue()
The value of this node, depending on its type; see the table above.
|
Document |
getOwnerDocument()
The
Document object associated with this node. |
Node |
getParentNode()
The parent of this node.
|
String |
getPrefix()
The namespace prefix of this node, or
null if it is
unspecified. |
Node |
getPreviousSibling()
The node immediately preceding this node.
|
protected QName |
getQName(String namespaceURI,
String qualifiedName) |
String |
getTagName()
The name of the element.
|
boolean |
hasAttribute(String name)
Returns
true when an attribute with a given name is
specified on this element or has a default value, false
otherwise. |
boolean |
hasAttributeNS(String namespaceURI,
String localName)
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. |
boolean |
hasAttributes()
Returns whether this node (if it is an element) has any attributes.
|
boolean |
hasChildNodes()
Returns whether this node has any children.
|
Node |
insertBefore(Node newChild,
Node refChild)
Inserts the node
newChild before the existing child node
refChild . |
boolean |
isSupported(String feature,
String version)
Tests whether the DOM implementation implements a specific feature and
that feature is supported by this node.
|
void |
removeAttribute(String name)
Removes an attribute by name.
|
Attr |
removeAttributeNode(Attr oldAttr)
Removes the specified attribute node.
|
void |
removeAttributeNS(String namespaceURI,
String localName)
Removes an attribute by local name and namespace URI.
|
Node |
removeChild(Node oldChild)
Removes the child node indicated by
oldChild from the list
of children, and returns it. |
Node |
replaceChild(Node newChild,
Node oldChild)
Replaces the child node
oldChild with newChild
in the list of children, and returns the oldChild node. |
void |
setAttribute(String name,
String value)
Adds a new attribute.
|
Attr |
setAttributeNode(Attr newAttr)
Adds a new attribute node.
|
Attr |
setAttributeNodeNS(Attr newAttr)
Adds a new attribute.
|
void |
setAttributeNS(String namespaceURI,
String qualifiedName,
String value)
Adds a new attribute.
|
void |
setNodeValue(String nodeValue) |
void |
setPrefix(String prefix) |
add, additionalNamespaces, additionalNamespaces, addNewNode, attribute, attribute, attribute, attribute, attributeCount, attributeIterator, attributeList, attributeList, attributes, clearContent, clone, contentList, declaredNamespaces, element, element, element, elementIterator, elementIterator, elementIterator, elementIterator, elements, elements, elements, elements, getDocument, getNamespaceForPrefix, getNamespaceForURI, getParent, getQName, getStringValue, getText, indexOf, node, nodeCount, nodeIterator, processingInstruction, processingInstructions, processingInstructions, remove, removeNode, removeProcessingInstruction, setAttributeList, setAttributes, setContent, setDocument, setParent, setQName, supportsParent
accept, add, add, add, add, add, add, add, add, addAttribute, addAttribute, addCDATA, addComment, addElement, addEntity, addNamespace, addNode, addProcessingInstruction, addProcessingInstruction, addText, appendAttributes, asXML, attributeValue, attributeValue, attributeValue, attributeValue, childAdded, childRemoved, createAttributeList, createAttributeList, createCopy, createCopy, createCopy, createElement, createElement, createSingleIterator, elementText, elementText, elementTextTrim, elementTextTrim, ensureAttributesCapacity, getData, getName, getNamespace, getNamespacePrefix, getNodeType, getPath, getQName, getQualifiedName, getUniquePath, getXPathNameStep, getXPathResult, hasMixedContent, isRootElement, isTextOnly, normalize, remove, remove, remove, remove, remove, remove, remove, remove, setAttributes, setAttributeValue, setAttributeValue, setData, setName, setNamespace, setText, toString, write
addElement, addElement, addElement, appendContent, content, contentRemoved, createContentList, createContentList, createEmptyList, createResultList, createSingleResultList, elementByID, elementID, getContentAsStringValue, getContentAsText, getTextTrim, hasContent, invalidNodeTypeAddException, isReadOnly, setProcessingInstructions
asXPathResult, createPattern, createXPath, createXPathFilter, createXPathResult, detach, getNodeTypeName, getPath, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getNodeType, normalize
getTextTrim
addElement, addElement, appendContent, content, elementByID, setProcessingInstructions
asXPathResult, createXPath, detach, getNodeTypeName, getPath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
private static final DocumentFactory DOCUMENT_FACTORY
DocumentFactory
instance used by defaultpublic DOMElement(String name)
public DOMElement(QName qname)
public DOMElement(QName qname, int attributeCount)
public DOMElement(String name, Namespace namespace)
public String getNamespaceURI()
Element
Returns the URI mapped to the namespace of this element
if one exists otherwise an empty String
is returned.
getNamespaceURI
in interface Element
getNamespaceURI
in class AbstractElement
Namespace
of this element
or an empty String
public String getPrefix()
Node
null
if it is
unspecified.
nodeName
attribute, which holds the qualified name, as
well as the tagName
and name
attributes of
the Element
and Attr
interfaces, when
applicable.
namespaceURI
and localName
do not change.
ELEMENT_NODE
and
ATTRIBUTE_NODE
and nodes created with a DOM Level 1
method, such as createElement
from the
Document
interface, this is always null
.public void setPrefix(String prefix) throws DOMException
DOMException
public String getLocalName()
Node
ELEMENT_NODE
and
ATTRIBUTE_NODE
and nodes created with a DOM Level 1
method, such as createElement
from the
Document
interface, this is always null
.public String getNodeName()
Node
public String getNodeValue() throws DOMException
Node
null
, setting it has no effect.DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.public void setNodeValue(String nodeValue) throws DOMException
DOMException
public Node getParentNode()
Node
Attr
,
Document
, DocumentFragment
,
Entity
, and Notation
may have a parent.
However, if a node has just been created and not yet added to the
tree, or if it has been removed from the tree, this is
null
.public NodeList getChildNodes()
Node
NodeList
that contains all children of this node. If
there are no children, this is a NodeList
containing no
nodes.public Node getFirstChild()
Node
null
.public Node getLastChild()
Node
null
.public Node getPreviousSibling()
Node
null
.public Node getNextSibling()
Node
null
.public NamedNodeMap getAttributes()
Node
NamedNodeMap
containing the attributes of this node (if
it is an Element
) or null
otherwise.public Document getOwnerDocument()
Node
Document
object associated with this node. This is
also the Document
object used to create new nodes. When
this node is a Document
or a DocumentType
which is not used with any Document
yet, this is
null
.public Node insertBefore(Node newChild, Node refChild) throws DOMException
Node
newChild
before the existing child node
refChild
. If refChild
is null
,
insert newChild
at the end of the list of children.
newChild
is a DocumentFragment
object,
all of its children are inserted, in the same order, before
refChild
. If the newChild
is already in the
tree, it is first removed.DOMException
- HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
allow children of the type of the newChild
node, or if
the node to insert is one of this node's ancestors.
newChild
was created
from a different document than the one that created this node.
refChild
is not a child of
this node.public Node replaceChild(Node newChild, Node oldChild) throws DOMException
Node
oldChild
with newChild
in the list of children, and returns the oldChild
node.
newChild
is a DocumentFragment
object,
oldChild
is replaced by all of the
DocumentFragment
children, which are inserted in the
same order. If the newChild
is already in the tree, it
is first removed.DOMException
- HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
allow children of the type of the newChild
node, or if
the node to put in is one of this node's ancestors.
newChild
was created
from a different document than the one that created this node.
oldChild
is not a child of
this node.public Node removeChild(Node oldChild) throws DOMException
Node
oldChild
from the list
of children, and returns it.DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
oldChild
is not a child of
this node.public Node appendChild(Node newChild) throws DOMException
Node
newChild
to the end of the list of children
of this node. If the newChild
is already in the tree, it
is first removed.DOMException
- HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
allow children of the type of the newChild
node, or if
the node to append is one of this node's ancestors.
newChild
was created
from a different document than the one that created this node.
public boolean hasChildNodes()
Node
true
if this node has any children,
false
otherwise.public Node cloneNode(boolean deep)
Node
parentNode
is null
.).
Element
copies all attributes and their
values, including those generated by the XML processor to represent
defaulted attributes, but this method does not copy any text it
contains unless it is a deep clone, since the text is contained in a
child Text
node. Cloning an Attribute
directly, as opposed to be cloned as part of an Element
cloning operation, returns a specified attribute (
specified
is true
). Cloning any other type
of node simply returns a copy of this node.
EntityReference
clone are readonly
. In addition, clones of unspecified Attr
nodes are
specified. And, cloning Document
,
DocumentType
, Entity
, and
Notation
nodes is implementation dependent.public boolean isSupported(String feature, String version)
Node
true
if the specified feature is
supported on this node, false
otherwise.public boolean hasAttributes()
Node
true
if this node has any attributes,
false
otherwise.public String getTagName()
Element
<elementExample id="demo"> ... </elementExample> ,
tagName
has
the value "elementExample"
. Note that this is
case-preserving in XML, as are all of the operations of the DOM. The
HTML DOM returns the tagName
of an HTML element in the
canonical uppercase form, regardless of the case in the source HTML
document.public String getAttribute(String name)
Element
Attr
value as a string, or the empty string
if that attribute does not have a specified or default value.public void setAttribute(String name, String value) throws DOMException
Element
Attr
node plus any
Text
and EntityReference
nodes, build the
appropriate subtree, and use setAttributeNode
to assign
it as the value of an attribute.
setAttributeNS
method.DOMException
- INVALID_CHARACTER_ERR: Raised if the specified name contains an
illegal character.
public void removeAttribute(String name) throws DOMException
Element
removeAttributeNS
method.DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.public Attr getAttributeNode(String name)
Element
getAttributeNodeNS
method.Attr
node with the specified name (
nodeName
) or null
if there is no such
attribute.public Attr setAttributeNode(Attr newAttr) throws DOMException
Element
nodeName
) is already present in the element, it is
replaced by the new one.
setAttributeNodeNS
method.newAttr
attribute replaces an existing
attribute, the replaced Attr
node is returned,
otherwise null
is returned.DOMException
- WRONG_DOCUMENT_ERR: Raised if newAttr
was created from a
different document than the one that created the element.
newAttr
is already an
attribute of another Element
object. The DOM user must
explicitly clone Attr
nodes to re-use them in other
elements.public Attr removeAttributeNode(Attr oldAttr) throws DOMException
Element
Attr
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, when applicable.Attr
node that was removed.DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
oldAttr
is not an attribute
of the element.public String getAttributeNS(String namespaceURI, String localName)
Element
Attr
value as a string, or the empty string
if that attribute does not have a specified or default value.public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException
Element
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
attribute.
DOMException
- INVALID_CHARACTER_ERR: Raised if the specified qualified name
contains an illegal character.
qualifiedName
is
malformed, if the qualifiedName
has a prefix and the
namespaceURI
is null
, if the
qualifiedName
has a prefix that is "xml" and the
namespaceURI
is different from "
http://www.w3.org/XML/1998/namespace", or if the
qualifiedName
is "xmlns" and the
namespaceURI
is different from "
http://www.w3.org/2000/xmlns/".public void removeAttributeNS(String namespaceURI, String localName) throws DOMException
Element
DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.public Attr getAttributeNodeNS(String namespaceURI, String localName)
Element
Attr
node by local name and namespace URI.
HTML-only DOM implementations do not need to implement this method.Attr
node with the specified attribute local
name and namespace URI or null
if there is no such
attribute.public Attr setAttributeNodeNS(Attr newAttr) throws DOMException
Element
newAttr
attribute replaces an existing
attribute with the same local name and namespace URI, the replaced
Attr
node is returned, otherwise null
is
returned.DOMException
- WRONG_DOCUMENT_ERR: Raised if newAttr
was created from a
different document than the one that created the element.
newAttr
is already an
attribute of another Element
object. The DOM user must
explicitly clone Attr
nodes to re-use them in other
elements.public NodeList getElementsByTagName(String name)
Element
NodeList
of all descendant Elements
with a given tag name, in the order in which they are encountered in
a preorder traversal of this Element
tree.Element
nodes.public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
Element
NodeList
of all the descendant
Elements
with a given local name and namespace URI in
the order in which they are encountered in a preorder traversal of
this Element
tree.
NodeList
object containing all the matched
Elements
.public boolean hasAttribute(String name)
Element
true
when an attribute with a given name is
specified on this element or has a default value, false
otherwise.true
if an attribute with the given name is
specified on this element or has a default value, false
otherwise.public boolean hasAttributeNS(String namespaceURI, String localName)
Element
true
when an attribute with a given local name and
namespace URI is specified on this element or has a default value,
false
otherwise. HTML-only DOM implementations do not
need to implement this method.true
if an attribute with the given local name
and namespace URI is specified or has a default value on this
element, false
otherwise.protected DocumentFactory getDocumentFactory()
getDocumentFactory
in class DefaultElement
protected Attribute createAttribute(Attr newAttr)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses