- Direct Known Subclasses:
ElementNSImpl,HTMLElementImpl
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 retrieve 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.
- Author:
- Arnaud Le Hors, IBM, Joe Kesselman, IBM, Andy Clark, IBM, Ralf Pfeiffer, IBM, Michael Glavassevich, IBM, Ronald Brill
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AttributeMapAttributes.protected StringElement name.Fields inherited from class org.htmlunit.cyberneko.xerces.dom.ParentNode
firstChild, fNodeListCache, ownerDocumentFields inherited from class org.htmlunit.cyberneko.xerces.dom.ChildNode
nextSibling_, previousSibling_Fields inherited from class org.htmlunit.cyberneko.xerces.dom.NodeImpl
DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_IS_CONTAINED, DOCUMENT_POSITION_PRECEDING, FIRSTCHILD, HASSTRING, ID, NORMALIZED, OWNED, ownerNode_, READONLY, SPECIFIED, SYNCCHILDRENFields 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_NODEFields inherited from interface org.w3c.dom.TypeInfo
DERIVATION_EXTENSION, DERIVATION_LIST, DERIVATION_RESTRICTION, DERIVATION_UNION -
Constructor Summary
ConstructorsConstructorDescriptionElementImpl(CoreDocumentImpl ownerDoc, String name) Constructs a defaultElementImplinstance. -
Method Summary
Modifier and TypeMethodDescriptioncloneNode(boolean deep) Returns a duplicate of a given node.getAttribute(String name) Look up a single Attribute by name.getAttributeNode(String name) Look up a single Attribute by name.getAttributeNodeNS(String namespaceURI, String localName) Retrieves an Attr node by local name and namespace URI.getAttributeNS(String namespaceURI, String localName) Introduced in DOM Level 2.Retrieve all the Attributes as a set.DOM Level 3 WD - Experimental.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.getElementsByTagNameNS(String namespaceURI, String localName) Introduced in DOM Level 2.Returns the name of this node.shortA short integer indicating what type of node this is.Method getSchemaTypeInfo.Returns the name of the Element.protected AttrbooleanhasAttribute(String name) Introduced in DOM Level 2.booleanhasAttributeNS(String namespaceURI, String localName) Introduced in DOM Level 2.booleanIntroduced in DOM Level 2.booleanisDerivedFrom(String typeNamespaceArg, String typeNameArg, int derivationMethod) Introduced in DOM Level 3.booleanisEqualNode(Node arg) DOM Level 3 WD- Experimental.voidremoveAttribute(String name) Remove the named attribute from this Element.removeAttributeNode(Attr oldAttr) Remove the specified attribute/value pair.voidremoveAttributeNS(String namespaceURI, String localName) Introduced in DOM Level 2.voidsetAttribute(String name, String value) Add a new name/value pair, or replace the value of the existing attribute having that name.setAttributeNode(Attr newAttr) Add a new attribute/value pair, or replace the value of the existing attribute with that name.setAttributeNodeNS(Attr newAttr) Introduced in DOM Level 2.voidsetAttributeNS(String namespaceURI, String qualifiedName, String value) Introduced in DOM Level 2.voidsetIdAttribute(String name, boolean makeId) DOM Level 3: register the given attribute node as an ID attribute.voidsetIdAttributeNode(Attr at, boolean makeId) DOM Level 3: register the given attribute node as an ID attribute.voidsetIdAttributeNS(String namespaceURI, String localName, boolean makeId) DOM Level 3: register the given attribute node as an ID attribute.protected voidNON-DOM set the ownerDocument of this node and its childrenMethods inherited from class org.htmlunit.cyberneko.xerces.dom.ParentNode
getChildNodes, getChildNodesUnoptimized, getFirstChild, getLastChild, getLength, getOwnerDocument, getTextContent, hasChildNodes, insertBefore, item, removeChild, replaceChild, setTextContent, synchronizeChildrenMethods inherited from class org.htmlunit.cyberneko.xerces.dom.ChildNode
getNextSibling, getParentNode, getPreviousSiblingMethods inherited from class org.htmlunit.cyberneko.xerces.dom.NodeImpl
addEventListener, appendChild, changed, changes, compareDocumentPosition, dispatchEvent, getFeature, getLocalName, getNamespaceURI, getNodeNumber, getNodeValue, getPrefix, getUserData, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, needsSyncChildren, normalize, removeEventListener, setNodeValue, setPrefix, setUserData, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.w3c.dom.Node
appendChild, 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, setUserData
-
Field Details
-
name_
Element name. -
attributes_
Attributes.
-
-
Constructor Details
-
ElementImpl
Constructs a defaultElementImplinstance.- Parameters:
ownerDoc- the owner documentname- the element name
-
-
Method Details
-
getNodeType
public short getNodeType()A short integer indicating what type of node this is. The named constants for this value are defined in the org.w3c.dom.Node interface. A short integer indicating what type of node this is. The named constants for this value are defined in the org.w3c.dom.Node interface.- Specified by:
getNodeTypein interfaceNode- Specified by:
getNodeTypein classNodeImpl
-
getNodeName
Returns the name of this node. Returns the element name.- Specified by:
getNodeNamein interfaceNode- Specified by:
getNodeNamein classNodeImpl
-
getAttributes
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.- Specified by:
getAttributesin interfaceNode- Overrides:
getAttributesin classNodeImpl
-
cloneNode
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.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.- Specified by:
cloneNodein interfaceNode- Overrides:
cloneNodein classParentNode- Parameters:
deep- whether to recursively clone all children in the subtree- Returns:
- the cloned node
- See Also:
-
getBaseURI
DOM Level 3 WD - Experimental. Retrieve baseURI.- Specified by:
getBaseURIin interfaceNode- Overrides:
getBaseURIin classNodeImpl
-
getXMLBaseAttribute
-
setOwnerDocument
Description copied from class:ParentNodeNON-DOM set the ownerDocument of this node and its children- Overrides:
setOwnerDocumentin classParentNode
-
getAttribute
Look up a single Attribute by name. Returns the Attribute's string value, or an empty string (NOT null!) to indicate that the name did not map to a currently defined attribute.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().
- Specified by:
getAttributein interfaceElement
-
getAttributeNode
Look up a single Attribute by name. Returns the Attribute Node, so its complete child tree is available. This could be important in XML, where the string rendering may not be sufficient information.If no matching attribute is available, returns null.
- Specified by:
getAttributeNodein interfaceElement
-
getElementsByTagName
Returns a NodeList of all descendent nodes (children, grandchildren, and so on) which are Elements and which have the specified tag name.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.
- Specified by:
getElementsByTagNamein interfaceElement- Parameters:
tagname- the type of element to gather- Returns:
- a NodeList containing all the matched Elements
- See Also:
-
getTagName
Returns the name of the Element. Note that Element.nodeName() is defined to also return the tag name.This is case-preserving in XML. HTML should uppercasify it on the way in.
- Specified by:
getTagNamein interfaceElement
-
removeAttribute
Remove the named attribute from this Element. If the removed Attribute has a default value, it is immediately replaced thereby.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.
- Specified by:
removeAttributein interfaceElement
-
removeAttributeNode
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, use removeAttribute().
- Specified by:
removeAttributeNodein interfaceElement- Returns:
- the Attribute object that was removed
- Throws:
DOMException- NOT_FOUND_ERR if oldattr is not an attribute of this Element
-
setAttribute
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.
- Specified by:
setAttributein interfaceElement- Parameters:
name- the name of the attributevalue- the value of the attribute- Throws:
DOMException- INVALID_NAME_ERR if the name is not acceptable
-
setAttributeNode
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.
- Specified by:
setAttributeNodein interfaceElement- Parameters:
newAttr- the attribute node to set- Returns:
- the replaced attribute node, or
null - Throws:
DOMException- INUSE_ATTRIBUTE_ERR if the Attribute object has already been assigned to another Element
-
getAttributeNS
Introduced in DOM Level 2.Retrieves an attribute value by local name and namespace URI.
- Specified by:
getAttributeNSin interfaceElement- Parameters:
namespaceURI- the namespace URI of the attribute to retrievelocalName- the local name of the attribute to retrieve- Returns:
- the Attr value as a string, or empty string if not specified or defaulted
-
setAttributeNS
Introduced in DOM Level 2.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". 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.
- Specified by:
setAttributeNSin interfaceElement- Parameters:
namespaceURI- the namespace URI of the attribute to create or alterqualifiedName- the qualified name of the attribute to create or altervalue- the value to set in string form
-
removeAttributeNS
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.
- Specified by:
removeAttributeNSin interfaceElement- Parameters:
namespaceURI- the namespace URI of the attribute to removelocalName- the local name of the attribute to remove
-
getAttributeNodeNS
Retrieves an Attr node by local name and namespace URI.- Specified by:
getAttributeNodeNSin interfaceElement- Parameters:
namespaceURI- the namespace URI of the attribute to retrievelocalName- the local name of the attribute to retrieve- Returns:
- the Attr node with the specified attribute local name and namespace URI, or
null
-
setAttributeNodeNS
Introduced in DOM Level 2.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.
- Specified by:
setAttributeNodeNSin interfaceElement- Parameters:
newAttr- the Attr node to add to the attribute list- Returns:
- the previously existing Attr node if replaced, or
nullotherwise - Throws:
DOMException- WRONG_DOCUMENT_ERR if newAttr was created from a different documentDOMException- INUSE_ATTRIBUTE_ERR if newAttr is already an attribute of another Element
-
hasAttributes
public boolean hasAttributes()Introduced in DOM Level 2.- Specified by:
hasAttributesin interfaceNode- Overrides:
hasAttributesin classNodeImpl
-
hasAttribute
Introduced in DOM Level 2.- Specified by:
hasAttributein interfaceElement
-
hasAttributeNS
Introduced in DOM Level 2.- Specified by:
hasAttributeNSin interfaceElement
-
getElementsByTagNameNS
Introduced in DOM Level 2.Returns a NodeList of all the Elements with a given local name and namespace URI in preorder traversal order starting from this node.
- Specified by:
getElementsByTagNameNSin interfaceElement- Parameters:
namespaceURI- 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.- Returns:
- NodeList A new NodeList object containing all the matched Elements.
-
isEqualNode
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 attributes.- Specified by:
isEqualNodein interfaceNode- Overrides:
isEqualNodein classParentNode
-
setIdAttributeNode
DOM Level 3: register the given attribute node as an ID attribute.- Specified by:
setIdAttributeNodein interfaceElement
-
setIdAttribute
DOM Level 3: register the given attribute node as an ID attribute.- Specified by:
setIdAttributein interfaceElement
-
setIdAttributeNS
DOM Level 3: register the given attribute node as an ID attribute.- Specified by:
setIdAttributeNSin interfaceElement
-
getTypeName
- Specified by:
getTypeNamein interfaceTypeInfo- See Also:
-
getTypeNamespace
- Specified by:
getTypeNamespacein interfaceTypeInfo- See Also:
-
isDerivedFrom
Introduced in DOM Level 3.Checks if a type is derived from another by restriction. See: http://www.w3.org/TR/DOM-Level-3-Core/core.html#TypeInfo-isDerivedFrom
- Specified by:
isDerivedFromin interfaceTypeInfo- Parameters:
typeNamespaceArg- the namespace of the ancestor type declarationtypeNameArg- the name of the ancestor type declarationderivationMethod- the derivation method- Returns:
trueif derived by restriction from the reference type,falseotherwise
-
getSchemaTypeInfo
Method getSchemaTypeInfo.- Specified by:
getSchemaTypeInfoin interfaceElement- Returns:
- TypeInfo
-