public class Element extends NodeImpl implements Node, Element
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| Modifier and Type | Method and Description |
|---|---|
void |
accept(XMLNodeVisitor visitor) |
void |
addAttribute(Attribute newAttr,
int index)
This api adds new attribute at a given index.
|
void |
appendAttribute(Attribute newAttr)
This api adds new attribute at the end.
|
Node |
appendChild(Node node)
Adds the node newChild to the end of the list of children of this node.
|
Node |
appendChild(Node node,
boolean consolidateNamespaces) |
protected void |
cloneNamespacePrefix(Map<Integer,String> allNS,
Map<String,String> prefixes) |
Element |
cloneNode(boolean deep,
boolean cloneNamespacePrefix) |
String |
getAttribute(String name)
Retrieves an attribute value by name.
|
Attribute |
getAttributeNode(String name)
Retrieves an attribute node by name.
|
Attribute |
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.
|
NodeList |
getElementsByTagName(String name)
Returns a
NodeList of all descendant Elements
with a given tag name, in document order. |
NodeList |
getElementsByTagNameNS(String namespaceURI,
String localName)
Returns a
NodeList of all the descendant
Elements with a given local name and namespace URI in
document order. |
String |
getLocalName() |
String |
getNodeName() |
short |
getNodeType() |
String |
getPrefix() |
TypeInfo |
getSchemaTypeInfo()
The type information associated with this element.
|
String |
getTagName() |
String |
getXmlFragmentText() |
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. |
Node |
insertBefore(Node newChild,
Node refChild)
Inserts the node newChild before the existing child node refChild.
|
void |
removeAttribute(String name)
Removes an attribute by name.
|
Attribute |
removeAttributeNode(Attr oldAttr)
Removes the specified attribute node.
|
void |
removeAttributeNS(String namespaceURI,
String localName)
Removes an attribute by local name and namespace URI.
|
void |
reorderAttribute(Attribute attr,
int index)
Moves attribute to the given index.
|
void |
reorderAttribute(int[] permutation)
Rearranges attribute list to the given permutaion.
|
void |
replaceAttribute(Attribute newAttr,
Attribute oldAttr)
This api replaces old attribute of this element with new attribute.
|
void |
setAttribute(String name,
String value)
Adds a new attribute.
|
Attribute |
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 |
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 |
setIdAttributeNode(Attr idAttr,
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 |
setLocalName(String localName) |
void |
setPrefix(String prefix) |
void |
setTagName(String tagName) |
void |
setXmlFragmentText(String text) |
addedToTree, assignNodeId, assignNodeIdRecursively, clone, cloneNamespacePrefixes, cloneNode, cloneNode, cloneShallowWithModelContext, compareDocumentPosition, copy, copyTokens, getAttributes, getAttributesForRead, getAttributesForWrite, getBaseURI, getChildNodes, getFeature, getFirstChild, getId, getIndexOfChild, getLastChild, getModel, getNamespaceURI, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPreviousSibling, getTextContent, getTokens, getUserData, hasAttributes, hasChildNodes, hashCode, isDefaultNamespace, isEqualNode, isEquivalentNode, isInTree, isSameNode, isSupported, lookupNamespace, lookupNamespace, lookupNamespaceURI, lookupPrefix, lookupPrefix, normalize, removeChild, reorderChild, reorderChildren, replaceChild, setNodeValue, setTextContent, setUserData, toStringclone, equals, finalize, getClass, notify, notifyAll, wait, wait, waitaddedToTree, clone, getId, getIndexOfChild, getNamespaceURI, isEquivalentNode, isInTreecloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setTextContent, setUserDatapublic short getNodeType()
getNodeType in interface NodegetNodeType in class NodeImplpublic String getNodeName()
getNodeName in interface NodegetNodeName in class NodeImplpublic void accept(XMLNodeVisitor visitor)
public String getTagName()
getTagName in interface Elementpublic void setTagName(String tagName)
public String getPrefix()
public void setPrefix(String prefix)
public String getLocalName()
getLocalName in interface NodegetLocalName in class NodeImplpublic void setLocalName(String localName)
public String getAttribute(String name)
getAttribute in interface Elementname - The name of the attribute to retrieve.Attr value as a string, or the empty string
if that attribute does not have a specified or default value.public Attribute getAttributeNode(String name)
getAttributeNodeNS method.getAttributeNode in interface Elementname - The name (nodeName) of the attribute to
retrieve.Attr node with the specified name (
nodeName) or null if there is no such
attribute.public boolean hasAttribute(String name)
true when an attribute with a given name is
specified on this element or has a default value, false
otherwise.hasAttribute in interface Elementname - The name of the attribute to look for.true if an attribute with the given name is
specified on this element or has a default value, false
otherwise.public String getAttributeNS(String namespaceURI, String localName)
null as the
namespaceURI parameter for methods if they wish to have
no namespace.getAttributeNS in interface ElementnamespaceURI - The namespace URI of the attribute to retrieve.localName - The local name of the attribute to retrieve.Attr value as a string, or the empty string
if that attribute does not have a specified or default value.DOMException - NOT_SUPPORTED_ERR: May be raised if the implementation does not
support the feature "XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).public Attribute getAttributeNodeNS(String namespaceURI, String localName)
Attr node by local name and namespace URI.
null as the
namespaceURI parameter for methods if they wish to have
no namespace.getAttributeNodeNS in interface ElementnamespaceURI - The namespace URI of the attribute to retrieve.localName - The local name of the attribute to retrieve.Attr node with the specified attribute local
name and namespace URI or null if there is no such
attribute.DOMException - NOT_SUPPORTED_ERR: May be raised if the implementation does not
support the feature "XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).public boolean hasAttributeNS(String namespaceURI, String localName)
true when an attribute with a given local name and
namespace URI is specified on this element or has a default value,
false otherwise.
null as the
namespaceURI parameter for methods if they wish to have
no namespace.hasAttributeNS in interface ElementnamespaceURI - The namespace URI of the attribute to look for.localName - The local name of the attribute to look for.true if an attribute with the given local name
and namespace URI is specified or has a default value on this
element, false otherwise.DOMException - NOT_SUPPORTED_ERR: May be raised if the implementation does not
support the feature "XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).public void setAttribute(String name, String value)
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.setAttribute in interface Elementname - The name of the attribute to create or alter.value - Value to set in string form.DOMException - INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
name according to the XML version in use specified in the
Document.xmlVersion attribute.
public Attribute setAttributeNode(Attr newAttr)
nodeName) is already present in the element, it is
replaced by the new one. Replacing an attribute node by itself has no
effect.
setAttributeNodeNS method.setAttributeNode in interface ElementnewAttr - The Attr node to add to the attribute list.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 void removeAttribute(String name)
Document.normalizeDocument() to guarantee this
information is up-to-date.
removeAttributeNS method.removeAttribute in interface Elementname - The name of the attribute to remove.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.public Attribute removeAttributeNode(Attr oldAttr)
Attr node is defined in the DTD, a new node
immediately appears with the default value as well as the
corresponding namespace URI, local name, and prefix when applicable.
The implementation may handle default values from other schemas
similarly but applications should use
Document.normalizeDocument() to guarantee this
information is up-to-date.removeAttributeNode in interface ElementoldAttr - The Attr node to remove from the attribute
list.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 Attr setAttributeNodeNS(Attr newAttr)
null as the
namespaceURI parameter for methods if they wish to have
no namespace.setAttributeNodeNS in interface ElementnewAttr - The Attr node to add to the attribute list.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.
"XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).public void setAttributeNS(String namespaceURI, String qualifiedName, String value)
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.
null as the
namespaceURI parameter for methods if they wish to have
no namespace.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.DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualified name is not
an XML name according to the XML version in use specified in the
Document.xmlVersion attribute.
qualifiedName is
malformed per the Namespaces in XML specification, 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", if the qualifiedName or its prefix is "xmlns" and the
namespaceURI is different from "http://www.w3.org/2000/xmlns/", or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the qualifiedName nor its prefix is "xmlns".
"XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).public void removeAttributeNS(String namespaceURI, String localName)
Document.normalizeDocument() to guarantee this
information is up-to-date.
null as the
namespaceURI parameter for methods if they wish to have
no namespace.removeAttributeNS in interface ElementnamespaceURI - The namespace URI of the attribute to remove.localName - The local name of the attribute to remove.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
"XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).public NodeList getElementsByTagName(String name)
NodeList of all descendant Elements
with a given tag name, in document order.getElementsByTagName in interface Elementname - The name of the tag to match on. The special value "*"
matches all tags.Element nodes.public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
NodeList of all the descendant
Elements with a given local name and namespace URI in
document order.getElementsByTagNameNS in interface ElementnamespaceURI - The namespace URI of the elements to match on. The
special value "*" matches all namespaces.localName - The local name of the elements to match on. The
special value "*" matches all local names.NodeList object containing all the matched
Elements.DOMException - NOT_SUPPORTED_ERR: May be raised if the implementation does not
support the feature "XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).public void setIdAttributeNode(Attr idAttr, boolean isId)
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.setIdAttributeNode in interface ElementidAttr - The attribute node.isId - Whether the attribute is a of type ID.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
public void setIdAttribute(String name, boolean isId)
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.
setIdAttributeNS method.setIdAttribute in interface Elementname - The name of the attribute.isId - Whether the attribute is a of type ID.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
public void setIdAttributeNS(String namespaceURI, String localName, boolean isId)
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.setIdAttributeNS in interface ElementnamespaceURI - The namespace URI of the attribute.localName - The local name of the attribute.isId - Whether the attribute is a of type ID.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
public TypeInfo getSchemaTypeInfo()
getSchemaTypeInfo in interface Elementpublic void replaceAttribute(Attribute newAttr, Attribute oldAttr)
newAttr - The new attribute.oldAttr - The old attribute to replace.IllegalStateException - if a newAttr has already been added to a tree.public void addAttribute(Attribute newAttr, int index)
newAttr - The new attribute to be added.index - The index at which attribute to be addedIndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).IllegalStateException - if a newAttr has already been added to a tree.public void reorderAttribute(Attribute attr, int index)
attr - The new attribute to be moved.index - The index at which attribute to be movedIndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).IllegalStateException - if a attr has not already been added to a tree.public void reorderAttribute(int[] permutation)
permutation - integer array with index represents current index and
value is final index after reordered.public void appendAttribute(Attribute newAttr)
newAttr - The new attribute to be added.IllegalStateException - if a newAttr has already been added to a tree.public Node appendChild(Node node)
NodeImplappendChild in interface NodeappendChild in class NodeImplpublic Node insertBefore(Node newChild, Node refChild) throws DOMException
NodeImplinsertBefore in interface NodeinsertBefore in class NodeImplnewChild - - The node to insert.refChild - - The reference node, i.e., the node before which the new node must be inserted.DOMExceptionpublic String getXmlFragmentText()
public void setXmlFragmentText(String text) throws IOException
IOExceptionpublic Element cloneNode(boolean deep, boolean cloneNamespacePrefix)
Built on May 16 2013. | Portions Copyright 1997-2013 Oracle. All rights reserved.