Package org.dom4j
Interface Element
- 
- All Known Implementing Classes:
 AbstractElement,BaseElement,BeanElement,DatatypeElement,DefaultElement,DOMElement,IndexedElement,NonLazyElement,UserDataElement
public interface Element extends Branch
Elementinterface defines an XML element. An element can have declared namespaces, attributes, child nodes and textual content.Some of this interface is optional. Some implementations may be read-only and not support being modified. Some implementations may not support the parent relationship and methods such as
Node.getParent()orNode.getDocument(). 
- 
- 
Field Summary
- 
Fields inherited from interface org.dom4j.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 
 - 
 
- 
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidadd(Attribute attribute)Adds the givenAttributeto this element.voidadd(CDATA cdata)Adds the givenCDATAto this element.voidadd(Entity entity)Adds the givenEntityto this element.voidadd(Namespace namespace)Adds the givenNamespaceto this element.voidadd(Text text)Adds the givenTextto this element.ElementaddAttribute(String name, String value)Adds the attribute value of the given local name.ElementaddAttribute(QName qName, String value)Adds the attribute value of the given fully qualified name.ElementaddCDATA(String cdata)Adds a newCDATAnode with the given text to this element.ElementaddComment(String comment)Adds a newCommentnode with the given text to this element.ElementaddEntity(String name, String text)Adds a newEntitynode with the given name and text to this element and returns a reference to the new node.List<Namespace>additionalNamespaces()Returns any additional namespaces declarations for this element other than namespace returned via thegetNamespace()method.ElementaddNamespace(String prefix, String uri)Adds a namespace to this element for use by its child contentElementaddProcessingInstruction(String target, String text)Adds a processing instruction for the given targetElementaddProcessingInstruction(String target, Map<String,String> data)Adds a processing instruction for the given targetElementaddText(String text)Adds a newTextnode with the given text to this element.voidappendAttributes(Element element)Appends the attributes of the given element to me.Attributeattribute(int index)Returns the attribute at the specified indexGets theAttributeattribute(String name)Returns the attribute with the given nameAttributeattribute(QName qName)DOCUMENT ME!intattributeCount()DOCUMENT ME!Iterator<Attribute>attributeIterator()DOCUMENT ME!List<Attribute>attributes()StringattributeValue(String name)This returns the attribute value for the attribute with the given name and any namespace or null if there is no such attribute or the empty string if the attribute value is empty.StringattributeValue(String name, String defaultValue)This returns the attribute value for the attribute with the given name and any namespace or the default value if there is no such attribute value.StringattributeValue(QName qName)This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.StringattributeValue(QName qName, String defaultValue)This returns the attribute value for the attribute with the given fully qualified name or the default value if there is no such attribute value.ElementcreateCopy()Creates a deep copy of this element The new element is detached from its parent, and getParent() on the clone will return null.ElementcreateCopy(String name)Creates a deep copy of this element with the given local name The new element is detached from its parent, and getParent() on the clone will return null.ElementcreateCopy(QName qName)Creates a deep copy of this element with the given fully qualified name.List<Namespace>declaredNamespaces()Returns all the namespaces declared by this element.Elementelement(String name)Returns the first element for the given local name and any namespace.Elementelement(QName qName)Returns the first element for the given fully qualified name.Iterator<Element>elementIterator()Returns an iterator over all this elements child elements.Iterator<Element>elementIterator(String name)Returns an iterator over the elements contained in this element which match the given local name and any namespace.Iterator<Element>elementIterator(QName qName)Returns an iterator over the elements contained in this element which match the given fully qualified name.List<Element>elements()Returns the elements contained in this element.List<Element>elements(String name)Returns the elements contained in this element with the given local name and any namespace.List<Element>elements(QName qName)Returns the elements contained in this element with the given fully qualified name.StringelementText(String name)StringelementText(QName qname)StringelementTextTrim(String name)StringelementTextTrim(QName qname)ObjectgetData()Accesses the data of this element which may implement data typing bindings such as XML Schema or Java Bean bindings or will return the same value asgetText()NamespacegetNamespace()Returns theNamespaceof this element if one exists otherwiseNamespace.NO_NAMESPACEis returned.NamespacegetNamespaceForPrefix(String prefix)Returns theNamespacewhich is mapped to the given prefix or null if it could not be found.NamespacegetNamespaceForURI(String uri)Returns theNamespacewhich is mapped to the given URI or null if it could not be found.StringgetNamespacePrefix()Returns the namespace prefix of this element if one exists otherwise an emptyStringis returned.List<Namespace>getNamespacesForURI(String uri)Returns the all namespaces which are mapped to the given URI or an empty list if no such namespaces could be found.StringgetNamespaceURI()Returns the URI mapped to the namespace of this element if one exists otherwise an emptyStringis returned.QNamegetQName()Returns theQNameof this element which represents the local name, the qualified name and theNamespace.QNamegetQName(String qualifiedName)Returns theQNamefor the given qualified name, using the namespace URI in scope for the given prefix of the qualified name or the default namespace if the qualified name has no prefix.StringgetQualifiedName()Returns the fully qualified name of this element.StringgetStringValue()Returns the XPath string-value of this node.StringgetText()Returns the text value of this element without recursing through child elements.StringgetTextTrim()DOCUMENT ME!NodegetXPathResult(int index)Returns a node at the given index suitable for an XPath result set.booleanhasMixedContent()Returns true if thisElementhas mixed content.booleanisRootElement()DOCUMENT ME!booleanisTextOnly()Returns true if thisElementhas text only content.booleanremove(Attribute attribute)Removes the givenAttributefrom this element.booleanremove(CDATA cdata)Removes the givenCDATAif the node is an immediate child of this element.booleanremove(Entity entity)Removes the givenEntityif the node is an immediate child of this element.booleanremove(Namespace namespace)Removes the givenNamespaceif the node is an immediate child of this element.booleanremove(Text text)Removes the givenTextif the node is an immediate child of this element.voidsetAttributes(List<Attribute> attributes)Sets the attributes that this element containsvoidsetAttributeValue(String name, String value)Deprecated.As of version 0.5.voidsetAttributeValue(QName qName, String value)Deprecated.As of version 0.5.voidsetData(Object data)Sets the data value of this element if this element supports data binding or callsNode.setText(java.lang.String)if it doesn'tvoidsetQName(QName qname)Sets theQNameof this element which represents the local name, the qualified name and theNamespace.- 
Methods inherited from interface org.dom4j.Branch
add, add, add, add, addElement, addElement, addElement, appendContent, clearContent, content, elementByID, indexOf, node, nodeCount, nodeIterator, normalize, processingInstruction, processingInstructions, processingInstructions, remove, remove, remove, remove, removeProcessingInstruction, setContent, setProcessingInstructions 
- 
Methods inherited from interface org.dom4j.Node
accept, asXML, asXPathResult, clone, createXPath, detach, getDocument, getName, getNodeType, getNodeTypeName, getParent, getPath, getPath, getUniquePath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, setDocument, setName, setParent, setText, supportsParent, valueOf, write 
 - 
 
 - 
 
- 
- 
Method Detail
- 
getQName
QName getQName()
Returns theQNameof this element which represents the local name, the qualified name and theNamespace.- Returns:
 - the 
QNameassociated with this element 
 
- 
setQName
void setQName(QName qname)
Sets theQNameof this element which represents the local name, the qualified name and theNamespace.- Parameters:
 qname- is theQNameto be associated with this element
 
- 
getNamespace
Namespace getNamespace()
Returns theNamespaceof this element if one exists otherwiseNamespace.NO_NAMESPACEis returned.- Returns:
 - the 
Namespaceassociated with this element 
 
- 
getQName
QName getQName(String qualifiedName)
Returns theQNamefor the given qualified name, using the namespace URI in scope for the given prefix of the qualified name or the default namespace if the qualified name has no prefix.- Parameters:
 qualifiedName- DOCUMENT ME!- Returns:
 - the 
QNamefor the given qualified name 
 
- 
getNamespaceForPrefix
Namespace getNamespaceForPrefix(String prefix)
Returns theNamespacewhich is mapped to the given prefix or null if it could not be found.- Parameters:
 prefix- DOCUMENT ME!- Returns:
 - the 
Namespaceassociated with the given prefix 
 
- 
getNamespaceForURI
Namespace getNamespaceForURI(String uri)
Returns theNamespacewhich is mapped to the given URI or null if it could not be found. If there is more than oneNamespacemapped to the URI, which of them will be returned is undetermined.- Parameters:
 uri- DOCUMENT ME!- Returns:
 - the 
Namespaceassociated with the given URI 
 
- 
getNamespacesForURI
List<Namespace> getNamespacesForURI(String uri)
Returns the all namespaces which are mapped to the given URI or an empty list if no such namespaces could be found.- Parameters:
 uri- DOCUMENT ME!- Returns:
 - the namespaces associated with the given URI
 - Since:
 - 1.5
 
 
- 
getNamespacePrefix
String getNamespacePrefix()
Returns the namespace prefix of this element if one exists otherwise an emptyStringis returned.- Returns:
 - the prefix of the 
Namespaceof this element or an emptyString 
 
- 
getNamespaceURI
String getNamespaceURI()
Returns the URI mapped to the namespace of this element if one exists otherwise an emptyStringis returned.- Returns:
 - the URI for the 
Namespaceof this element or an emptyString 
 
- 
getQualifiedName
String getQualifiedName()
Returns the fully qualified name of this element. This will be the same as the value returned fromNode.getName()if this element has no namespace attached to this element or an expression of the formgetNamespacePrefix() + ":" + getName()
will be returned.- Returns:
 - the fully qualified name of the element.
 
 
- 
additionalNamespaces
List<Namespace> additionalNamespaces()
Returns any additional namespaces declarations for this element other than namespace returned via thegetNamespace()method. If no additional namespace declarations are present for this element then an empty list will be returned. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.- Returns:
 - a list of any additional namespace declarations.
 
 
- 
declaredNamespaces
List<Namespace> declaredNamespaces()
Returns all the namespaces declared by this element. If no namespaces are declared for this element then an empty list will be returned. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.- Returns:
 - a list of namespaces declared for this element.
 
 
- 
addAttribute
Element addAttribute(String name, String value)
Adds the attribute value of the given local name. If an attribute already exists for the given name it will be replaced. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the given name.- Parameters:
 name- is the name of the attribute whose value is to be added or updatedvalue- is the attribute's value- Returns:
 - this 
Elementinstance. 
 
- 
addAttribute
Element addAttribute(QName qName, String value)
Adds the attribute value of the given fully qualified name. If an attribute already exists for the given name it will be replaced. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the given name.- Parameters:
 qName- is the fully qualified name of the attribute whose value is to be added or updatedvalue- is the attribute's value- Returns:
 - this 
Elementinstance. 
 
- 
addComment
Element addComment(String comment)
Adds a newCommentnode with the given text to this element.- Parameters:
 comment- is the text for theCommentnode.- Returns:
 - this 
Elementinstance. 
 
- 
addCDATA
Element addCDATA(String cdata)
Adds a newCDATAnode with the given text to this element.- Parameters:
 cdata- is the text for theCDATAnode.- Returns:
 - this 
Elementinstance. 
 
- 
addEntity
Element addEntity(String name, String text)
Adds a newEntitynode with the given name and text to this element and returns a reference to the new node.- Parameters:
 name- is the name for theEntitynode.text- is the text for theEntitynode.- Returns:
 - this 
Elementinstance. 
 
- 
addNamespace
Element addNamespace(String prefix, String uri)
Adds a namespace to this element for use by its child content- Parameters:
 prefix- is the prefix to use, which should not be null or blankuri- is the namespace URI- Returns:
 - this 
Elementinstance. 
 
- 
addProcessingInstruction
Element addProcessingInstruction(String target, String text)
Adds a processing instruction for the given target- Parameters:
 target- is the target of the processing instructiontext- is the textual data (key/value pairs) of the processing instruction- Returns:
 - this 
Elementinstance. 
 
- 
addProcessingInstruction
Element addProcessingInstruction(String target, Map<String,String> data)
Adds a processing instruction for the given target- Parameters:
 target- is the target of the processing instructiondata- is a Map of the key / value pairs of the processing instruction- Returns:
 - this 
Elementinstance. 
 
- 
addText
Element addText(String text)
Adds a newTextnode with the given text to this element.- Parameters:
 text- is the text for theTextnode.- Returns:
 - this 
Elementinstance. 
 
- 
add
void add(Attribute attribute)
Adds the givenAttributeto this element. If the given node already has a parent defined then anIllegalAddExceptionwill be thrown. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the QName of this attribute.- Parameters:
 attribute- is the attribute to be added
 
- 
add
void add(CDATA cdata)
Adds the givenCDATAto this element. If the given node already has a parent defined then anIllegalAddExceptionwill be thrown.- Parameters:
 cdata- is the CDATA to be added
 
- 
add
void add(Entity entity)
Adds the givenEntityto this element. If the given node already has a parent defined then anIllegalAddExceptionwill be thrown.- Parameters:
 entity- is the entity to be added
 
- 
add
void add(Text text)
Adds the givenTextto this element. If the given node already has a parent defined then anIllegalAddExceptionwill be thrown.- Parameters:
 text- is the text to be added
 
- 
add
void add(Namespace namespace)
Adds the givenNamespaceto this element. If the given node already has a parent defined then anIllegalAddExceptionwill be thrown.- Parameters:
 namespace- is the namespace to be added
 
- 
remove
boolean remove(Attribute attribute)
Removes the givenAttributefrom this element.- Parameters:
 attribute- is the attribute to be removed- Returns:
 - true if the attribute was removed
 
 
- 
remove
boolean remove(CDATA cdata)
Removes the givenCDATAif the node is an immediate child of this element. If the given node is not an immediate child of this element then theNode.detach()method should be used instead.- Parameters:
 cdata- is the CDATA to be removed- Returns:
 - true if the cdata was removed
 
 
- 
remove
boolean remove(Entity entity)
Removes the givenEntityif the node is an immediate child of this element. If the given node is not an immediate child of this element then theNode.detach()method should be used instead.- Parameters:
 entity- is the entity to be removed- Returns:
 - true if the entity was removed
 
 
- 
remove
boolean remove(Namespace namespace)
Removes the givenNamespaceif the node is an immediate child of this element. If the given node is not an immediate child of this element then theNode.detach()method should be used instead.- Parameters:
 namespace- is the namespace to be removed- Returns:
 - true if the namespace was removed
 
 
- 
remove
boolean remove(Text text)
Removes the givenTextif the node is an immediate child of this element. If the given node is not an immediate child of this element then theNode.detach()method should be used instead.- Parameters:
 text- is the text to be removed- Returns:
 - true if the text was removed
 
 
- 
getText
String getText()
 
- 
getTextTrim
String getTextTrim()
DOCUMENT ME!- Returns:
 - the trimmed text value where whitespace is trimmed and normalised into single spaces. This method does not return null.
 
 
- 
getStringValue
String getStringValue()
Returns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification . This method returns the string-value of all the containedText,CDATA,EntityandElementnodes all appended together.- Specified by:
 getStringValuein interfaceNode- Returns:
 - the text from all the child Text and Element nodes appended together.
 
 
- 
getData
Object getData()
Accesses the data of this element which may implement data typing bindings such as XML Schema or Java Bean bindings or will return the same value asgetText()- Returns:
 - DOCUMENT ME!
 
 
- 
setData
void setData(Object data)
Sets the data value of this element if this element supports data binding or callsNode.setText(java.lang.String)if it doesn't- Parameters:
 data- DOCUMENT ME!
 
- 
attributes
List<Attribute> attributes()
Returns theAttributeinstances this element contains as a backedListso that the attributes may be modified directly using theListinterface. TheListis backed by theElementso that changes to the list are reflected in the element and vice versa.- Returns:
 - the attributes that this element contains as a 
List 
 
- 
setAttributes
void setAttributes(List<Attribute> attributes)
Sets the attributes that this element contains- Parameters:
 attributes- DOCUMENT ME!
 
- 
attributeCount
int attributeCount()
DOCUMENT ME!- Returns:
 - the number of attributes this element contains
 
 
- 
attributeIterator
Iterator<Attribute> attributeIterator()
DOCUMENT ME!- Returns:
 - an iterator over the attributes of this element
 
 
- 
attribute
Attribute attribute(int index)
Returns the attribute at the specified indexGets the- Parameters:
 index- DOCUMENT ME!- Returns:
 - the attribute at the specified index where index >= 0 and index < number of attributes or throws an IndexOutOfBoundsException if the index is not within the allowable range
 
 
- 
attribute
Attribute attribute(String name)
Returns the attribute with the given name- Parameters:
 name- DOCUMENT ME!- Returns:
 - the attribute for the given local name in any namespace. If there are more than one attributes with the given local name in different namespaces then the first one is returned.
 
 
- 
attribute
Attribute attribute(QName qName)
DOCUMENT ME!- Parameters:
 qName- is the fully qualified name- Returns:
 - the attribute for the given fully qualified name or null if it could not be found.
 
 
- 
attributeValue
String attributeValue(String name)
This returns the attribute value for the attribute with the given name and any namespace or null if there is no such attribute or the empty string if the attribute value is empty.- Parameters:
 name- is the name of the attribute value to be returned- Returns:
 - the value of the attribute, null if the attribute does not exist or the empty string
 
 
- 
attributeValue
String attributeValue(String name, String defaultValue)
This returns the attribute value for the attribute with the given name and any namespace or the default value if there is no such attribute value.- Parameters:
 name- is the name of the attribute value to be returneddefaultValue- is the default value to be returned if the attribute has no value defined.- Returns:
 - the value of the attribute or the defaultValue if the attribute has no value defined.
 
 
- 
attributeValue
String attributeValue(QName qName)
This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.- Parameters:
 qName- is the fully qualified name- Returns:
 - the value of the attribute, null if the attribute does not exist or the empty string
 
 
- 
attributeValue
String attributeValue(QName qName, String defaultValue)
This returns the attribute value for the attribute with the given fully qualified name or the default value if there is no such attribute value.- Parameters:
 qName- is the fully qualified namedefaultValue- is the default value to be returned if the attribute has no value defined.- Returns:
 - the value of the attribute or the defaultValue if the attribute has no value defined.
 
 
- 
setAttributeValue
void setAttributeValue(String name, String value)
Deprecated.As of version 0.5. Please useaddAttribute(String, String)instead. WILL BE REMOVED IN dom4j-1.6 !!Sets the attribute value of the given local name.- Parameters:
 name- is the name of the attribute whose value is to be added or updatedvalue- is the attribute's value
 
- 
setAttributeValue
void setAttributeValue(QName qName, String value)
Deprecated.As of version 0.5. Please useaddAttribute(QName, String)instead. WILL BE REMOVED IN dom4j-1.6 !!Sets the attribute value of the given fully qualified name.- Parameters:
 qName- is the fully qualified name of the attribute whose value is to be added or updatedvalue- is the attribute's value
 
- 
element
Element element(String name)
Returns the first element for the given local name and any namespace.- Parameters:
 name- DOCUMENT ME!- Returns:
 - the first element with the given local name
 
 
- 
element
Element element(QName qName)
Returns the first element for the given fully qualified name.- Parameters:
 qName- is the fully qualified name to search for- Returns:
 - the first element with the given fully qualified name
 
 
- 
elements
List<Element> elements()
Returns the elements contained in this element. If this element does not contain any elements then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.- Returns:
 - a list of all the elements in this element.
 
 
- 
elements
List<Element> elements(String name)
Returns the elements contained in this element with the given local name and any namespace. If no elements are found then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.- Parameters:
 name- DOCUMENT ME!- Returns:
 - a list of all the elements in this element for the given local name
 
 
- 
elements
List<Element> elements(QName qName)
Returns the elements contained in this element with the given fully qualified name. If no elements are found then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.- Parameters:
 qName- is the fully qualified name to search for- Returns:
 - a list of all the elements in this element for the given fully qualified name.
 
 
- 
elementIterator
Iterator<Element> elementIterator()
Returns an iterator over all this elements child elements.- Returns:
 - an iterator over the contained elements
 
 
- 
elementIterator
Iterator<Element> elementIterator(String name)
Returns an iterator over the elements contained in this element which match the given local name and any namespace.- Parameters:
 name- DOCUMENT ME!- Returns:
 - an iterator over the contained elements matching the given local name
 
 
- 
elementIterator
Iterator<Element> elementIterator(QName qName)
Returns an iterator over the elements contained in this element which match the given fully qualified name.- Parameters:
 qName- is the fully qualified name to search for- Returns:
 - an iterator over the contained elements matching the given fully qualified name
 
 
- 
isRootElement
boolean isRootElement()
DOCUMENT ME!- Returns:
 - true if this element is the root element of a document and this element supports the parent relationship else false.
 
 
- 
hasMixedContent
boolean hasMixedContent()
Returns true if thisElementhas mixed content. Mixed content means that an element contains both textual data and child elements.- Returns:
 - true if this element contains mixed content.
 
 
- 
isTextOnly
boolean isTextOnly()
Returns true if thisElementhas text only content.- Returns:
 - true if this element is empty or only contains text content.
 
 
- 
appendAttributes
void appendAttributes(Element element)
Appends the attributes of the given element to me. This method behaves like theCollection.addAll(java.util.Collection)method.- Parameters:
 element- is the element whose attributes will be added to me.
 
- 
createCopy
Element createCopy()
Creates a deep copy of this element The new element is detached from its parent, and getParent() on the clone will return null.- Returns:
 - a new deep copy Element
 
 
- 
createCopy
Element createCopy(String name)
Creates a deep copy of this element with the given local name The new element is detached from its parent, and getParent() on the clone will return null.- Parameters:
 name- DOCUMENT ME!- Returns:
 - a new deep copy Element
 
 
- 
createCopy
Element createCopy(QName qName)
Creates a deep copy of this element with the given fully qualified name. The new element is detached from its parent, and getParent() on the clone will return null.- Parameters:
 qName- DOCUMENT ME!- Returns:
 - a new deep copy Element
 
 
- 
getXPathResult
Node getXPathResult(int index)
Returns a node at the given index suitable for an XPath result set. This means the resulting Node will either be null or it will support the parent relationship.- Parameters:
 index- DOCUMENT ME!- Returns:
 - the Node for the given index which will support the parent relationship or null if there is not a node at the given index.
 
 
 - 
 
 -