public class ElementImpl extends ParentNode implements Element, TypeInfo
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 it, does.
ElementNSImpl| Modifier and Type | Field and Description |
|---|---|
protected AttributeMap |
attributes
Attributes.
|
protected String |
name
Element name.
|
firstChild, fNodeListCache, ownerDocumentnextSibling, previousSiblingDOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_IS_CONTAINED, DOCUMENT_POSITION_PRECEDING, ELEMENT_DEFINITION_NODE, FIRSTCHILD, flags, HASSTRING, ID, IGNORABLEWS, NORMALIZED, OWNED, ownerNode, READONLY, SPECIFIED, SYNCCHILDREN, SYNCDATAATTRIBUTE_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_NODEDERIVATION_EXTENSION, DERIVATION_LIST, DERIVATION_RESTRICTION, DERIVATION_UNION| Constructor and Description |
|---|
ElementImpl(CoreDocumentImpl ownerDoc,
String name) |
| Modifier and Type | Method and Description |
|---|---|
Node |
cloneNode(boolean deep)
Returns a duplicate of a given node.
|
String |
getAttribute(String name)
Look up a single Attribute by name.
|
Attr |
getAttributeNode(String name)
Look up a single Attribute by name.
|
Attr |
getAttributeNodeNS(String namespaceURI,
String localName)
Retrieves an Attr node by local name and namespace URI.
|
String |
getAttributeNS(String namespaceURI,
String localName)
Introduced in DOM Level 2.
|
NamedNodeMap |
getAttributes()
Return the collection of attributes associated with this node,
or null if none.
|
String |
getBaseURI()
The absolute base URI of this node or
null if undefined. |
int |
getChildElementCount() |
protected NamedNodeMapImpl |
getDefaultAttributes() |
NodeList |
getElementsByTagName(String tagname)
Returns a NodeList of all descendent nodes (children,
grandchildren, and so on) which are Elements and which have the
specified tag name.
|
NodeList |
getElementsByTagNameNS(String namespaceURI,
String localName)
Introduced in DOM Level 2.
|
Element |
getFirstElementChild() |
Element |
getLastElementChild() |
Element |
getNextElementSibling() |
String |
getNodeName()
the name of this node.
|
short |
getNodeType()
A short integer indicating what type of node this is.
|
Element |
getPreviousElementSibling() |
TypeInfo |
getSchemaTypeInfo()
Method getSchemaTypeInfo.
|
String |
getTagName()
Returns the name of the Element.
|
String |
getTypeName() |
String |
getTypeNamespace() |
protected Attr |
getXMLBaseAttribute() |
boolean |
hasAttribute(String name)
Introduced in DOM Level 2.
|
boolean |
hasAttributeNS(String namespaceURI,
String localName)
Introduced in DOM Level 2.
|
boolean |
hasAttributes()
Returns whether this node (if it is an element) has any attributes.
|
boolean |
isDerivedFrom(String typeNamespaceArg,
String typeNameArg,
int derivationMethod)
Introduced in DOM Level 3.
|
boolean |
isEqualNode(Node arg)
Tests whether two nodes are equal.
|
protected void |
reconcileDefaultAttributes()
Reconcile default attributes.
|
void |
removeAttribute(String name)
Remove the named attribute from this Element.
|
Attr |
removeAttributeNode(Attr oldAttr)
Remove the specified attribute/value pair.
|
void |
removeAttributeNS(String namespaceURI,
String localName)
Introduced in DOM Level 2.
|
void |
setAttribute(String name,
String value)
Add a new name/value pair, or replace the value of the existing
attribute having that name.
|
Attr |
setAttributeNode(Attr newAttr)
Add a new attribute/value pair, or replace the value of the
existing attribute with that name.
|
Attr |
setAttributeNodeNS(Attr newAttr)
Introduced in DOM Level 2.
|
void |
setAttributeNS(String namespaceURI,
String qualifiedName,
String value)
Introduced in DOM Level 2.
|
void |
setIdAttribute(String name,
boolean makeId)
DOM Level 3: register the given attribute node as an ID attribute
|
void |
setIdAttributeNode(Attr at,
boolean makeId)
DOM Level 3: register the given attribute node as an ID attribute
|
void |
setIdAttributeNS(String namespaceURI,
String localName,
boolean makeId)
DOM Level 3: register the given attribute node as an ID attribute
|
protected void |
setOwnerDocument(CoreDocumentImpl doc)
NON-DOM set the ownerDocument of this node and its children
|
void |
setReadOnly(boolean readOnly,
boolean deep)
NON-DOM: PR-DOM-Level-1-19980818 mentions readonly nodes in conjunction
with Entities, but provides no API to support this.
|
protected void |
setupDefaultAttributes()
Setup the default attributes.
|
protected void |
synchronizeData()
Override this method in subclass to hook in efficient
internal data structure.
|
getChildNodes, getChildNodesUnoptimized, getFirstChild, getLastChild, getLength, getOwnerDocument, getTextContent, hasChildNodes, insertBefore, item, removeChild, replaceChild, setTextContent, synchronizeChildrengetNextSibling, getParentNode, getPreviousSiblingaddEventListener, appendChild, changed, changes, compareDocumentPosition, dispatchEvent, getFeature, getLocalName, getNamespaceURI, getNodeNumber, getNodeValue, getPrefix, getReadOnly, getUserData, getUserData, getUserDataRecord, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, needsSyncChildren, normalize, removeEventListener, setNodeValue, setPrefix, setUserData, setUserData, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitappendChild, compareDocumentPosition, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasChildNodes, insertBefore, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserDataprotected String name
protected AttributeMap attributes
public ElementImpl(CoreDocumentImpl ownerDoc, String name)
public short getNodeType()
getNodeType in interface NodegetNodeType in class NodeImplpublic String getNodeName()
getNodeName in interface NodegetNodeName in class NodeImplpublic NamedNodeMap getAttributes()
getAttributes in interface NodegetAttributes in class NodeImplElementImplpublic Node cloneNode(boolean deep)
Note: since we never have any children deep is meaningless here, ParentNode overrides this behavior. Returns a duplicate of a given node. You can consider this a generic "copy constructor" for nodes. The newly returned object should be completely independent of the source object's subtree, so changes in one after the clone has been made will not affect the other.
Note: since we never have any children deep is meaningless here, ParentNode overrides this behavior. Returns a duplicate of a given node. You can consider this a generic "copy constructor" for nodes. The newly returned object should be completely independent of the source object's subtree, so changes in one after the clone has been made will not affect the other.
Example: Cloning a Text node will copy both the node and the text it contains.
Example: Cloning something that has children -- Element or Attr, for example -- will _not_ clone those children unless a "deep clone" has been requested. A shallow clone of an Attr node will yield an empty Attr of the same name.
NOTE: Clones will always be read/write, even if the node being cloned is read-only, to permit applications using only the DOM API to obtain editable copies of locked portions of the tree. Return a duplicate copy of this Element. Note that its children will not be copied unless the "deep" flag is true, but Attributes are always replicated.
cloneNode in interface NodecloneNode in class ParentNodeNode.cloneNode(boolean)public String getBaseURI()
null if undefined.
This value is computed according to . However, when the
Document supports the feature "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.
Element, a Document
or a a ProcessingInstruction, this attribute represents
the properties [base URI] defined in . When the node is a
Notation, an Entity, or an
EntityReference, this attribute represents the
properties [declaration base URI] in the . How will this be affected
by resolution of relative namespace URIs issue?It's not.Should this
only be on Document, Element, ProcessingInstruction, Entity, and
Notation nodes, according to the infoset? If not, what is it equal to
on other nodes? Null? An empty string? I think it should be the
parent's.No.Should this be read-only and computed or and actual
read-write attribute?Read-only and computed (F2F 19 Jun 2000 and
teleconference 30 May 2001).If the base HTML element is not yet
attached to a document, does the insert change the Document.baseURI?
Yes. (F2F 26 Sep 2001)
DOM Level 3 WD - Experimental.
Retrieve baseURIgetBaseURI in interface NodegetBaseURI in class NodeImplprotected Attr getXMLBaseAttribute()
protected void setOwnerDocument(CoreDocumentImpl doc)
ParentNodesetOwnerDocument in class ParentNodepublic String getAttribute(String name)
Note: Attributes may contain complex node trees. This method returns the "flattened" string obtained from Attribute.getValue(). If you need the structure information, see getAttributeNode().
getAttribute in interface Elementpublic Attr getAttributeNode(String name)
If no matching attribute is available, returns null.
getAttributeNode in interface Elementpublic NodeList getElementsByTagName(String tagname)
Note: NodeList is a "live" view of the DOM. Its contents will change as the DOM changes, and alterations made to the NodeList will be reflected in the DOM.
getElementsByTagName in interface Elementtagname - The type of element to gather. To obtain a list of
all elements no matter what their names, use the wild-card tag
name "*".DeepNodeListImplpublic String getTagName()
This is case-preserving in XML. HTML should uppercasify it on the way in.
getTagName in interface Elementpublic void removeAttribute(String name)
The default logic is actually implemented in NamedNodeMapImpl. PR-DOM-Level-1-19980818 doesn't fully address the DTD, so some of this behavior is likely to change in future versions. ?????
Note that this call "succeeds" even if no attribute by this name existed -- unlike removeAttributeNode, which will throw a not-found exception in that case.
removeAttribute in interface ElementDOMException - NO_MODIFICATION_ALLOWED_ERR if the node is
readonly.public Attr removeAttributeNode(Attr oldAttr) throws DOMException
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, use removeAttribute().
removeAttributeNode in interface ElementDOMException - NOT_FOUND_ERR if oldattr is not an attribute of
this Element.DOMException - NO_MODIFICATION_ALLOWED_ERR if the node is
readonly.public void setAttribute(String name, String value)
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.
setAttribute in interface ElementDOMException - INVALID_NAME_ERR if the name is not acceptable.
(Attribute factory will do that test for us.)DOMException - NO_MODIFICATION_ALLOWED_ERR if the node is
readonly.public Attr setAttributeNode(Attr newAttr) throws DOMException
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.
setAttributeNode in interface ElementDOMException - INUSE_ATTRIBUTE_ERR if the Attribute object
has already been assigned to another Element.public String getAttributeNS(String namespaceURI, String localName)
Retrieves an attribute value by local name and namespace URI.
getAttributeNS in interface ElementnamespaceURI - The namespace URI of the attribute to
retrieve.localName - The local name of the attribute to retrieve.public void setAttributeNS(String namespaceURI, String qualifiedName, String value)
Adds a new attribute. If the given namespaceURI is null or an empty string and the qualifiedName has a prefix that is "xml", the new attribute is bound to the 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 attribute.
setAttributeNS in interface ElementnamespaceURI - The namespace URI of the attribute to create
or alter.qualifiedName - The qualified name of the attribute to create or
alter.value - The value to set in string form.public void removeAttributeNS(String namespaceURI, String localName)
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.
removeAttributeNS in interface ElementnamespaceURI - The namespace URI of the attribute to remove.localName - The local name of the attribute to remove.public Attr getAttributeNodeNS(String namespaceURI, String localName)
getAttributeNodeNS in interface ElementnamespaceURI - The namespace URI of the attribute to
retrieve.localName - The local name of the attribute to retrieve.public Attr setAttributeNodeNS(Attr newAttr) throws DOMException
Adds a new attribute. If an attribute with that local name and namespace URI is already present in the element, it is replaced by the new one.
setAttributeNodeNS in interface ElementnewAttr - The Attr node to add to the attribute list. When
the Node has no namespaceURI, this method behaves
like setAttributeNode.DOMException - WRONG_DOCUMENT_ERR: Raised if newAttr
was created from a different document than the one that
created the element.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if
this node is readonly.DOMException - INUSE_ATTRIBUTE_ERR: Raised if 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 boolean hasAttributes()
hasAttributes in interface NodehasAttributes in class NodeImpltrue if this node has any attributes,
false otherwise.ElementImplpublic boolean hasAttribute(String name)
hasAttribute in interface Elementpublic boolean hasAttributeNS(String namespaceURI, String localName)
hasAttributeNS in interface Elementpublic NodeList getElementsByTagNameNS(String namespaceURI, String localName)
Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the Document tree, starting from this node.
getElementsByTagNameNS in interface ElementnamespaceURI - The namespace URI of the elements to match
on. The special value "*" matches all
namespaces. When it is null or an empty
string, this method behaves like
getElementsByTagName.localName - The local name of the elements to match on.
The special value "*" matches all local names.public boolean isEqualNode(Node arg)
Node.isSameNode. All nodes that are the same
will also be equal, though the reverse may not be true.
nodeName, localName,
namespaceURI, prefix, nodeValue
, baseURI. 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. This is true
for Attr nodes as for any other type of node. Note that
normalization can affect equality; to avoid this, nodes should be
normalized before being compared.
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.
ownerDocument attribute, the specified
attribute for Attr nodes, the
isWhitespaceInElementContent attribute for
Text nodes, as well as any user data or event listeners
registered on the nodes.
DOM Level 3 WD- Experimental.
Override inherited behavior from NodeImpl to support deep equal.
DOM Level 3 WD- Experimental.
Override inherited behavior from NodeImpl and ParentNode to check on
attributesisEqualNode in interface NodeisEqualNode in class ParentNodearg - The node to compare equality with.true otherwise false.public void setIdAttributeNode(Attr at, boolean makeId)
setIdAttributeNode in interface Elementpublic void setIdAttribute(String name, boolean makeId)
setIdAttribute in interface Elementpublic void setIdAttributeNS(String namespaceURI, String localName, boolean makeId)
setIdAttributeNS in interface Elementpublic String getTypeName()
getTypeName in interface TypeInfoTypeInfo.getTypeName()public String getTypeNamespace()
getTypeNamespace in interface TypeInfoTypeInfo.getTypeNamespace()public boolean isDerivedFrom(String typeNamespaceArg, String typeNameArg, int derivationMethod)
Checks if a type is derived from another by restriction. See: http://www.w3.org/TR/DOM-Level-3-Core/core.html#TypeInfo-isDerivedFrom
isDerivedFrom in interface TypeInfotypeNamespaceArg - The namspace of the ancestor type declarationtypeNameArg - The name of the ancestor type declarationderivationMethod - The derivation methodpublic TypeInfo getSchemaTypeInfo()
getSchemaTypeInfo in interface Elementpublic void setReadOnly(boolean readOnly,
boolean deep)
Most DOM users should not touch this method. Its anticpated use is during construction of EntityRefernces, where it will be used to lock the contents replicated from Entity so they can't be casually altered. It _could_ be published as a DOM extension, if desired.
Note: since we never have any children deep is meaningless here, ParentNode overrides this behavior. Override default behavior so that if deep is true, children are also toggled. NON-DOM: Subclassed to flip the attributes' readonly switch as well.
setReadOnly in class ParentNodereadOnly - True or false as desired.deep - If true, children are also toggled. Note that this will
not change the state of an EntityReference or its children,
which are always read-only.NodeImpl.setReadOnly(boolean, boolean)protected void synchronizeData()
synchronizeData in class NodeImplprotected void setupDefaultAttributes()
protected void reconcileDefaultAttributes()
protected NamedNodeMapImpl getDefaultAttributes()
public final int getChildElementCount()
public final Element getFirstElementChild()
Elementpublic final Element getLastElementChild()
Elementpublic final Element getNextElementSibling()
Elementpublic final Element getPreviousElementSibling()
ElementCopyright © 2023 Gargoyle Software Inc.. All rights reserved.