gnu.xml.dom

Class DomElement

Implemented Interfaces:
Cloneable, Comparable<T>, DocumentEvent, Element, EventTarget, Node, NodeList
Known Direct Subclasses:
DomHTMLElement

public class DomElement
extends DomNsNode
implements Element

"Element" implementation.

Fields inherited from 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

Constructor Summary

DomElement(DomDocument owner, String namespaceURI, String name)
Constructs an Element node associated with the specified document.
DomElement(DomDocument owner, String namespaceURI, String name, String prefix, String localName)
Constructs an Element node associated with the specified document.

Method Summary

Object
clone()
Shallow clone of the element, except that associated attributes are (deep) cloned.
String
getAttribute(String name)
DOM L1 Returns the value of the specified attribute, or an empty string.
String
getAttributeNS(String namespaceURI, String local)
DOM L2 Returns the value of the specified attribute, or an empty string.
Attr
getAttributeNode(String name)
DOM L1 Returns the appropriate attribute node; the name is the nodeName property of the attribute.
Attr
getAttributeNodeNS(String namespace, String localPart)
DOM L2 Returns the appropriate attribute node; the name combines the namespace name and the local part.
NamedNodeMap
getAttributes()
DOM L1 Returns the element's attributes
String
getBaseURI()
The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI.
TypeInfo
getSchemaTypeInfo()
The type information associated with this element.
String
getTagName()
DOM L1 Returns the element name (same as getNodeName).
boolean
hasAttribute(String name)
DOM L2 Returns true if the element has an attribute with the specified name (specified or DTD defaulted).
boolean
hasAttributeNS(String namespaceURI, String local)
DOM L2 Returns true if the element has an attribute with the specified name (specified or DTD defaulted).
boolean
hasAttributes()
DOM L2> Returns true iff this is an element node with attributes.
boolean
isDefaultNamespace(String namespaceURI)
This method checks if the specified namespaceURI is the default namespace or not.
boolean
isEqualNode(Node arg)
Tests whether two nodes are equal.
String
lookupNamespaceURI(String prefix)
Look up the namespace URI associated to the given prefix, starting from this node.
String
lookupPrefix(String namespaceURI)
Look up the prefix associated to the given namespace URI, starting from this node.
void
makeReadonly()
Marks this element, its children, and its associated attributes as readonly.
void
removeAttribute(String name)
DOM L1 Removes the appropriate attribute node.
void
removeAttributeNS(String namespace, String localPart)
DOM L2 Removes the appropriate attribute node; the name combines the namespace name and the local part.
Attr
removeAttributeNode(Attr node)
DOM L1 Removes the appropriate attribute node; the name is the nodeName property of the attribute.
void
setAttribute(String name, String value)
DOM L1 Modifies an existing attribute to have the specified value, or creates a new one with that value.
void
setAttributeNS(String uri, String aname, String value)
DOM L2 Modifies an existing attribute to have the specified value, or creates a new one with that value.
Attr
setAttributeNode(Attr attr)
DOM L1 Stores the specified attribute, optionally overwriting any existing one with that name.
Attr
setAttributeNodeNS(Attr attr)
DOM L2 Stores the specified attribute, optionally overwriting any existing one with that name.
void
setIdAttribute(String name, boolean isId)
If the parameter isId is true, this method declares the specified attribute to be a user-determined ID attribute .
void
setIdAttributeNS(String namespaceURI, String localName, boolean isId)
If the parameter isId is true, this method declares the specified attribute to be a user-determined ID attribute .
void
setIdAttributeNode(Attr attr, boolean isId)
If the parameter isId is true, this method declares the specified attribute to be a user-determined ID attribute .

Methods inherited from class gnu.xml.dom.DomNsNode

getLocalName, getNamespaceURI, getNodeName, getPrefix, setPrefix

Methods inherited from class gnu.xml.dom.DomNode

addEventListener, appendChild, clone, cloneNode, compact, compareDocumentPosition, compareTo, createEvent, dispatchEvent, getAttributes, getBaseURI, getChildNodes, getElementsByTagName, getElementsByTagNameNS, getFeature, getFirstChild, getLastChild, getLength, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isReadonly, isSameNode, isSupported, item, list, lookupNamespaceURI, lookupPrefix, makeReadonly, nameAndTypeEquals, normalize, removeChild, removeEventListener, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData, toString, trimToSize

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

DomElement

protected DomElement(DomDocument owner,
                     String namespaceURI,
                     String name)
Constructs an Element node associated with the specified document.

This constructor should only be invoked by a Document as part of its createElement functionality, or through a subclass which is similarly used in a "Sub-DOM" style layer.

Parameters:
owner - The document with which this node is associated
namespaceURI - Combined with the local part of the name, this is used to uniquely identify a type of element
name - Name of this element, which may include a prefix

DomElement

protected DomElement(DomDocument owner,
                     String namespaceURI,
                     String name,
                     String prefix,
                     String localName)
Constructs an Element node associated with the specified document. This constructor should only be invoked by a Document as part of its createElement functionality, or through a subclass which is similarly used in a "Sub-DOM" style layer.

With this constructor, the prefix and local part are given explicitly rather than being computed. This allows them to be explicitly set to null as required by Document.createElement(String).

Parameters:
owner - The document with which this node is associated
namespaceURI - Combined with the local part of the name, this is used to uniquely identify a type of element
name - Name of this element, which may include a prefix
prefix - the namespace prefix of the name. May be null.
localName - the local part of the name. May be null.

Method Details

clone

public Object clone()
Shallow clone of the element, except that associated attributes are (deep) cloned.
Overrides:
clone in interface DomNode

getAttribute

public String getAttribute(String name)
DOM L1 Returns the value of the specified attribute, or an empty string.
Specified by:
getAttribute in interface Element

getAttributeNS

public String getAttributeNS(String namespaceURI,
                             String local)
DOM L2 Returns the value of the specified attribute, or an empty string.
Specified by:
getAttributeNS in interface Element

getAttributeNode

public Attr getAttributeNode(String name)
DOM L1 Returns the appropriate attribute node; the name is the nodeName property of the attribute.
Specified by:
getAttributeNode in interface Element

getAttributeNodeNS

public Attr getAttributeNodeNS(String namespace,
                               String localPart)
DOM L2 Returns the appropriate attribute node; the name combines the namespace name and the local part.
Specified by:
getAttributeNodeNS in interface Element

getAttributes

public NamedNodeMap getAttributes()
DOM L1 Returns the element's attributes
Specified by:
getAttributes in interface Node
Overrides:
getAttributes in interface DomNode

getBaseURI

public String getBaseURI()
The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI. This value is computed as described in . However, when the Document supports the feature "HTML" [DOM Level 2 HTML] , the base URI is computed using first the value of the href attribute of the HTML BASE element if any, and the value of the documentURI attribute from the Document interface otherwise.
Specified by:
getBaseURI in interface Node
Overrides:
getBaseURI in interface DomNode
Since:
DOM Level 3

getSchemaTypeInfo

public TypeInfo getSchemaTypeInfo()
The type information associated with this element.
Specified by:
getSchemaTypeInfo in interface Element
Since:
DOM Level 3

getTagName

public final String getTagName()
DOM L1 Returns the element name (same as getNodeName).
Specified by:
getTagName in interface Element

hasAttribute

public boolean hasAttribute(String name)
DOM L2 Returns true if the element has an attribute with the specified name (specified or DTD defaulted).
Specified by:
hasAttribute in interface Element

hasAttributeNS

public boolean hasAttributeNS(String namespaceURI,
                              String local)
DOM L2 Returns true if the element has an attribute with the specified name (specified or DTD defaulted).
Specified by:
hasAttributeNS in interface Element

hasAttributes

public boolean hasAttributes()
DOM L2> Returns true iff this is an element node with attributes.
Specified by:
hasAttributes in interface Node
Overrides:
hasAttributes in interface DomNode

isDefaultNamespace

public boolean isDefaultNamespace(String namespaceURI)
This method checks if the specified namespaceURI is the default namespace or not.
Specified by:
isDefaultNamespace in interface Node
Overrides:
isDefaultNamespace in interface DomNode
Parameters:
namespaceURI - The namespace URI to look for.
Returns:
Returns true if the specified namespaceURI is the default namespace, false otherwise.
Since:
DOM Level 3

isEqualNode

public boolean isEqualNode(Node arg)
Tests whether two nodes are equal.
This method tests for equality of nodes, not sameness (i.e., whether the two nodes are references to the same object) which can be tested with Node.isSameNode(). All nodes that are the same will also be equal, though the reverse may not be true.
Two nodes are equal if and only if the following conditions are satisfied:
  • The two nodes are of the same type.
  • The following string attributes are equal: nodeName, localName, namespaceURI, prefix, nodeValue . This is: they are both null, or they have the same length and are character for character identical.
  • The attributes NamedNodeMaps are equal. This is: they are both null, or they have the same length and for each node that exists in one map there is a node that exists in the other map and is equal, although not necessarily at the same index.
  • The childNodes NodeLists are equal. This is: they are both null, or they have the same length and contain equal nodes at the same index. Note that normalization can affect equality; to avoid this, nodes should be normalized before being compared.

For two DocumentType nodes to be equal, the following conditions must also be satisfied:
  • The following string attributes are equal: publicId, systemId, internalSubset.
  • The entities NamedNodeMaps are equal.
  • The notations NamedNodeMaps are equal.

On the other hand, the following do not affect equality: the ownerDocument, baseURI, and parentNode attributes, the specified attribute for Attr nodes, the schemaTypeInfo attribute for Attr and Element nodes, the Text.isElementContentWhitespace attribute for Text nodes, as well as any user data or event listeners registered on the nodes.

Note: As a general rule, anything not mentioned in the description above is not significant in consideration of equality checking. Note that future versions of this specification may take into account more attributes and implementations conform to this specification are expected to be updated accordingly.

Specified by:
isEqualNode in interface Node
Overrides:
isEqualNode in interface DomNode
Parameters:
arg - The node to compare equality with.
Returns:
Returns true if the nodes are equal, false otherwise.
Since:
DOM Level 3

lookupNamespaceURI

public String lookupNamespaceURI(String prefix)
Look up the namespace URI associated to the given prefix, starting from this node.
See for details on the algorithm used by this method.
Specified by:
lookupNamespaceURI in interface Node
Overrides:
lookupNamespaceURI in interface DomNode
Parameters:
prefix - The prefix to look for. If this parameter is null, the method will return the default namespace URI if any.
Returns:
Returns the associated namespace URI or null if none is found.
Since:
DOM Level 3

lookupPrefix

public String lookupPrefix(String namespaceURI)
Look up the prefix associated to the given namespace URI, starting from this node. The default namespace declarations are ignored by this method.
See for details on the algorithm used by this method.
Specified by:
lookupPrefix in interface Node
Overrides:
lookupPrefix in interface DomNode
Parameters:
namespaceURI - The namespace URI to look for.
Returns:
Returns an associated namespace prefix if found or null if none is found. If more than one prefix are associated to the namespace prefix, the returned namespace prefix is implementation dependent.
Since:
DOM Level 3

makeReadonly

public void makeReadonly()
Marks this element, its children, and its associated attributes as readonly.
Overrides:
makeReadonly in interface DomNode

removeAttribute

public void removeAttribute(String name)
DOM L1 Removes the appropriate attribute node. If there is no such node, this is (bizarrely enough) a NOP so you won't see exceptions if your code deletes non-existent attributes.

Note that since there is no portable way for DOM to record DTD information, default values for attributes will never be provided automatically.

Specified by:
removeAttribute in interface Element

removeAttributeNS

public void removeAttributeNS(String namespace,
                              String localPart)
DOM L2 Removes the appropriate attribute node; the name combines the namespace name and the local part.

Note that since there is no portable way for DOM to record DTD information, default values for attributes will never be provided automatically.

Specified by:
removeAttributeNS in interface Element

removeAttributeNode

public Attr removeAttributeNode(Attr node)
DOM L1 Removes the appropriate attribute node; the name is the nodeName property of the attribute.

Note that since there is no portable way for DOM to record DTD information, default values for attributes will never be provided automatically.

Specified by:
removeAttributeNode in interface Element

setAttribute

public void setAttribute(String name,
                         String value)
DOM L1 Modifies an existing attribute to have the specified value, or creates a new one with that value. The name used is the nodeName value.
Specified by:
setAttribute in interface Element

setAttributeNS

public void setAttributeNS(String uri,
                           String aname,
                           String value)
DOM L2 Modifies an existing attribute to have the specified value, or creates a new one with that value.
Specified by:
setAttributeNS in interface Element

setAttributeNode

public Attr setAttributeNode(Attr attr)
DOM L1 Stores the specified attribute, optionally overwriting any existing one with that name.
Specified by:
setAttributeNode in interface Element

setAttributeNodeNS

public Attr setAttributeNodeNS(Attr attr)
DOM L2 Stores the specified attribute, optionally overwriting any existing one with that name.
Specified by:
setAttributeNodeNS in interface Element

setIdAttribute

public void setIdAttribute(String name,
                           boolean isId)
If the parameter isId is true, this method declares the specified attribute to be a user-determined ID attribute . This affects the value of Attr.isId and the behavior of Document.getElementById, but does not change any schema that may be in use, in particular this does not affect the Attr.schemaTypeInfo of the specified Attr node. Use the value false for the parameter isId to undeclare an attribute for being a user-determined ID attribute.
To specify an attribute by local name and namespace URI, use the setIdAttributeNS method.
Specified by:
setIdAttribute in interface Element
Parameters:
name - The name of the attribute.
isId - Whether the attribute is a of type ID.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised if the specified node is not an attribute of this element.
Since:
DOM Level 3

setIdAttributeNS

public void setIdAttributeNS(String namespaceURI,
                             String localName,
                             boolean isId)
If the parameter isId is true, this method declares the specified attribute to be a user-determined ID attribute . This affects the value of Attr.isId and the behavior of Document.getElementById, but does not change any schema that may be in use, in particular this does not affect the Attr.schemaTypeInfo of the specified Attr node. Use the value false for the parameter isId to undeclare an attribute for being a user-determined ID attribute.
Specified by:
setIdAttributeNS in interface Element
Parameters:
namespaceURI - The namespace URI of the attribute.
localName - The local name of the attribute.
isId - Whether the attribute is a of type ID.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised if the specified node is not an attribute of this element.
Since:
DOM Level 3

setIdAttributeNode

public void setIdAttributeNode(Attr attr,
                               boolean isId)
If the parameter isId is true, this method declares the specified attribute to be a user-determined ID attribute . This affects the value of Attr.isId and the behavior of Document.getElementById, but does not change any schema that may be in use, in particular this does not affect the Attr.schemaTypeInfo of the specified Attr node. Use the value false for the parameter isId to undeclare an attribute for being a user-determined ID attribute.
Specified by:
setIdAttributeNode in interface Element
Parameters:
isId - Whether the attribute is a of type ID.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised if the specified node is not an attribute of this element.
Since:
DOM Level 3

DomElement.java -- Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.