Class DefaultElement
- java.lang.Object
 - 
- org.dom4j.tree.AbstractNode
 - 
- org.dom4j.tree.AbstractBranch
 - 
- org.dom4j.tree.AbstractElement
 - 
- org.dom4j.tree.DefaultElement
 
 
 
 
 
- 
- All Implemented Interfaces:
 Serializable,Cloneable,Branch,Element,Node
- Direct Known Subclasses:
 BeanElement,DatatypeElement,DOMElement,IndexedElement,UserDataElement
public class DefaultElement extends AbstractElement
DefaultElementis the default DOM4J default implementation of an XML element.- See Also:
 - Serialized Form
 
 
- 
- 
Field Summary
- 
Fields inherited from class org.dom4j.tree.AbstractElement
USE_STRINGVALUE_SEPARATOR, VERBOSE_TOSTRING 
- 
Fields inherited from class org.dom4j.tree.AbstractBranch
DEFAULT_CONTENT_LIST_SIZE 
- 
Fields inherited from class org.dom4j.tree.AbstractNode
NODE_TYPE_NAMES 
- 
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 
 - 
 
- 
Constructor Summary
Constructors Constructor Description DefaultElement(String name)DefaultElement(String name, Namespace namespace)DefaultElement(QName qname)DefaultElement(QName qname, int attributeCount) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Attribute attribute)Adds the givenAttributeto this element.List<Namespace>additionalNamespaces()Returns any additional namespaces declarations for this element other than namespace returned via theElement.getNamespace()method.List<Namespace>additionalNamespaces(String defaultNamespaceURI)protected voidaddNewNode(Node node)Like addNode() but does not require a parent checkAttributeattribute(int index)Returns the attribute at the specified indexGets theAttributeattribute(String name)Returns the attribute with the given nameAttributeattribute(String name, Namespace namespace)Attributeattribute(QName qName)DOCUMENT ME!intattributeCount()DOCUMENT ME!Iterator<Attribute>attributeIterator()DOCUMENT ME!protected List<Attribute>attributeList()DOCUMENT ME!protected List<Attribute>attributeList(int size)DOCUMENT ME!List<Attribute>attributes()voidclearContent()Clears the content for this branch, removing anyNodeinstances this branch may contain.Objectclone()clonewill return a deep clone or if this node is read-only then clone will return the same instance.protected List<Node>contentList()DOCUMENT ME!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(String name, Namespace namespace)Elementelement(QName qName)Returns the first element for the given fully qualified name.DocumentgetDocument()getDocumentreturns theDocumentthat thisNodeis part of if this node supports the parent relationship.protected DocumentFactorygetDocumentFactory()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.ElementgetParent()getParentreturns the parentElementif this node supports the parent relationship or null if it is the root element or does not support the parent relationship.QNamegetQName()Returns theQNameof this element which represents the local name, the qualified name and theNamespace.StringgetStringValue()Returns the XPath string-value of this node.StringgetText()Returns the text of this node.intindexOf(Node node)Returns the index of the given node if it is a child node of this branch or -1 if the given node is not a child node.Nodenode(int index)Returns theNodeat the specified index position.intnodeCount()Returns the number ofNodeinstances that this branch contains.Iterator<Node>nodeIterator()Returns an iterator through the content nodes of this branchProcessingInstructionprocessingInstruction(String target)DOCUMENT ME!List<ProcessingInstruction>processingInstructions()Returns a list of all the processing instructions in this branch.List<ProcessingInstruction>processingInstructions(String target)Returns a list of the processing instructions for the given target.booleanremove(Attribute attribute)Removes the givenAttributefrom this element.protected booleanremoveNode(Node node)booleanremoveProcessingInstruction(String target)Removes the processing instruction for the given target if it existsprotected voidsetAttributeList(List<Attribute> attributeList)voidsetAttributes(List<Attribute> attributes)Sets the attributes that this element containsvoidsetContent(List<Node> content)Sets the contents of this branch as aListofNodeinstances.voidsetDocument(Document document)setDocumentsets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.voidsetParent(Element parent)setParentsets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.voidsetQName(QName name)Sets theQNameof this element which represents the local name, the qualified name and theNamespace.booleansupportsParent()supportsParentreturns true if this node supports the parent relationship.- 
Methods inherited from class org.dom4j.tree.AbstractElement
accept, add, add, add, add, add, add, add, add, addAttribute, addAttribute, addCDATA, addComment, addElement, addEntity, addNamespace, addNewNode, addNode, addNode, addProcessingInstruction, addProcessingInstruction, addText, appendAttributes, asXML, attributeValue, attributeValue, attributeValue, attributeValue, childAdded, childRemoved, createAttributeList, createAttributeList, createCopy, createCopy, createCopy, createElement, createElement, createSingleIterator, elementIterator, elementIterator, elementIterator, elementIterator, elements, elements, elements, elements, elementText, elementText, elementTextTrim, elementTextTrim, ensureAttributesCapacity, getData, getName, getNamespace, getNamespacePrefix, getNamespacesForURI, getNamespaceURI, getNodeType, getPath, getQName, getQualifiedName, getUniquePath, getXPathNameStep, getXPathResult, hasMixedContent, isRootElement, isTextOnly, normalize, remove, remove, remove, remove, remove, remove, remove, remove, setAttributes, setAttributeValue, setAttributeValue, setData, setName, setNamespace, setText, toString, write 
- 
Methods inherited from class org.dom4j.tree.AbstractBranch
addElement, addElement, addElement, appendContent, content, contentRemoved, createContentList, createContentList, createEmptyList, createResultList, createSingleResultList, elementByID, elementID, getContentAsStringValue, getContentAsText, getTextTrim, hasContent, invalidNodeTypeAddException, isReadOnly, setProcessingInstructions 
- 
Methods inherited from class org.dom4j.tree.AbstractNode
asXPathResult, createPattern, createXPath, createXPathFilter, createXPathResult, detach, getNodeTypeName, getPath, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf 
- 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
- 
Methods inherited from interface org.dom4j.Branch
addElement, addElement, appendContent, content, elementByID, setProcessingInstructions 
- 
Methods inherited from interface org.dom4j.Element
getTextTrim 
- 
Methods inherited from interface org.dom4j.Node
asXPathResult, createXPath, detach, getNodeTypeName, getPath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf 
 - 
 
 - 
 
- 
- 
Method Detail
- 
getParent
public Element getParent()
Description copied from interface:NodegetParentreturns the parentElementif this node supports the parent relationship or null if it is the root element or does not support the parent relationship.This method is an optional feature and may not be supported for all
Nodeimplementations.- Specified by:
 getParentin interfaceNode- Overrides:
 getParentin classAbstractNode- Returns:
 - the parent of this node or null if it is the root of the tree or the parent relationship is not supported.
 
 
- 
setParent
public void setParent(Element parent)
Description copied from interface:NodesetParentsets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.This method should only be called from inside an
Elementimplementation method and is not intended for general use.- Specified by:
 setParentin interfaceNode- Overrides:
 setParentin classAbstractNode- Parameters:
 parent- is the new parent of this node.
 
- 
getDocument
public Document getDocument()
Description copied from interface:NodegetDocumentreturns theDocumentthat thisNodeis part of if this node supports the parent relationship.This method is an optional feature and may not be supported for all
Nodeimplementations.- Specified by:
 getDocumentin interfaceNode- Overrides:
 getDocumentin classAbstractNode- Returns:
 - the document of this node or null if this feature is not
         supported or the node is not associated with a
         
Document 
 
- 
setDocument
public void setDocument(Document document)
Description copied from interface:NodesetDocumentsets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.This method should only be called from inside a
Documentimplementation method and is not intended for general use.- Specified by:
 setDocumentin interfaceNode- Overrides:
 setDocumentin classAbstractNode- Parameters:
 document- is the new document of this node.
 
- 
supportsParent
public boolean supportsParent()
Description copied from interface:NodesupportsParentreturns true if this node supports the parent relationship.Some XML tree implementations are singly linked and only support downward navigation through children relationships. The default case is that both parent and children relationships are supported though for memory and performance reasons the parent relationship may not be supported.
- Specified by:
 supportsParentin interfaceNode- Overrides:
 supportsParentin classAbstractNode- Returns:
 - true if this node supports the parent relationship or false it is not supported
 
 
- 
getQName
public QName getQName()
Description copied from interface:ElementReturns theQNameof this element which represents the local name, the qualified name and theNamespace.- Returns:
 - the 
QNameassociated with this element 
 
- 
setQName
public void setQName(QName name)
Description copied from interface:ElementSets theQNameof this element which represents the local name, the qualified name and theNamespace.- Parameters:
 name- is theQNameto be associated with this element
 
- 
getText
public String getText()
Description copied from interface:NodeReturns the text of this node.
 
- 
getStringValue
public String getStringValue()
Description copied from interface:NodeReturns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification .- Specified by:
 getStringValuein interfaceElement- Specified by:
 getStringValuein interfaceNode- Overrides:
 getStringValuein classAbstractElement- Returns:
 - the text from all the child Text and Element nodes appended together.
 
 
- 
clone
public Object clone()
Description copied from interface:Nodeclonewill return a deep clone or if this node is read-only then clone will return the same instance.- Specified by:
 clonein interfaceNode- Overrides:
 clonein classAbstractNode- Returns:
 - a deep clone of myself or myself if I am read only.
 
 
- 
getNamespaceForPrefix
public Namespace getNamespaceForPrefix(String prefix)
Description copied from interface:ElementReturns theNamespacewhich is mapped to the given prefix or null if it could not be found.- Specified by:
 getNamespaceForPrefixin interfaceElement- Overrides:
 getNamespaceForPrefixin classAbstractElement- Parameters:
 prefix- DOCUMENT ME!- Returns:
 - the 
Namespaceassociated with the given prefix 
 
- 
getNamespaceForURI
public Namespace getNamespaceForURI(String uri)
Description copied from interface:ElementReturns 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.- Specified by:
 getNamespaceForURIin interfaceElement- Overrides:
 getNamespaceForURIin classAbstractElement- Parameters:
 uri- DOCUMENT ME!- Returns:
 - the 
Namespaceassociated with the given URI 
 
- 
declaredNamespaces
public List<Namespace> declaredNamespaces()
Description copied from interface:ElementReturns 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.- Specified by:
 declaredNamespacesin interfaceElement- Overrides:
 declaredNamespacesin classAbstractElement- Returns:
 - a list of namespaces declared for this element.
 
 
- 
additionalNamespaces
public List<Namespace> additionalNamespaces()
Description copied from interface:ElementReturns any additional namespaces declarations for this element other than namespace returned via theElement.getNamespace()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.- Specified by:
 additionalNamespacesin interfaceElement- Overrides:
 additionalNamespacesin classAbstractElement- Returns:
 - a list of any additional namespace declarations.
 
 
- 
additionalNamespaces
public List<Namespace> additionalNamespaces(String defaultNamespaceURI)
- Overrides:
 additionalNamespacesin classAbstractElement
 
- 
processingInstructions
public List<ProcessingInstruction> processingInstructions()
Description copied from interface:BranchReturns a list of all the processing instructions in this branch. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.- Specified by:
 processingInstructionsin interfaceBranch- Overrides:
 processingInstructionsin classAbstractElement- Returns:
 - a backed list of the processing instructions
 
 
- 
processingInstructions
public List<ProcessingInstruction> processingInstructions(String target)
Description copied from interface:BranchReturns a list of the processing instructions for the given target. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.- Specified by:
 processingInstructionsin interfaceBranch- Overrides:
 processingInstructionsin classAbstractElement- Parameters:
 target- DOCUMENT ME!- Returns:
 - a backed list of the processing instructions
 
 
- 
processingInstruction
public ProcessingInstruction processingInstruction(String target)
Description copied from interface:BranchDOCUMENT ME!- Specified by:
 processingInstructionin interfaceBranch- Overrides:
 processingInstructionin classAbstractElement- Parameters:
 target- DOCUMENT ME!- Returns:
 - the processing instruction for the given target
 
 
- 
removeProcessingInstruction
public boolean removeProcessingInstruction(String target)
Description copied from interface:BranchRemoves the processing instruction for the given target if it exists- Specified by:
 removeProcessingInstructionin interfaceBranch- Overrides:
 removeProcessingInstructionin classAbstractElement- Parameters:
 target- DOCUMENT ME!- Returns:
 - true if a processing instruction was removed else false
 
 
- 
element
public Element element(String name)
Description copied from interface:ElementReturns the first element for the given local name and any namespace.- Specified by:
 elementin interfaceElement- Overrides:
 elementin classAbstractElement- Parameters:
 name- DOCUMENT ME!- Returns:
 - the first element with the given local name
 
 
- 
element
public Element element(QName qName)
Description copied from interface:ElementReturns the first element for the given fully qualified name.- Specified by:
 elementin interfaceElement- Overrides:
 elementin classAbstractElement- Parameters:
 qName- is the fully qualified name to search for- Returns:
 - the first element with the given fully qualified name
 
 
- 
element
public Element element(String name, Namespace namespace)
- Overrides:
 elementin classAbstractElement
 
- 
setContent
public void setContent(List<Node> content)
Description copied from interface:BranchSets the contents of this branch as aListofNodeinstances.- Parameters:
 content- is the list of nodes to use as the content for this branch.
 
- 
clearContent
public void clearContent()
Description copied from interface:BranchClears the content for this branch, removing anyNodeinstances this branch may contain. 
- 
node
public Node node(int index)
Description copied from interface:BranchReturns theNodeat the specified index position.- Specified by:
 nodein interfaceBranch- Overrides:
 nodein classAbstractElement- Parameters:
 index- the index of the node to return.- Returns:
 - the 
Nodeat the specified position. 
 
- 
indexOf
public int indexOf(Node node)
Description copied from interface:BranchReturns the index of the given node if it is a child node of this branch or -1 if the given node is not a child node.- Specified by:
 indexOfin interfaceBranch- Overrides:
 indexOfin classAbstractElement- Parameters:
 node- the content child node to find.- Returns:
 - the index of the given node starting at 0 or -1 if the node is not a child node of this branch
 
 
- 
nodeCount
public int nodeCount()
Description copied from interface:BranchReturns the number ofNodeinstances that this branch contains.- Specified by:
 nodeCountin interfaceBranch- Overrides:
 nodeCountin classAbstractElement- Returns:
 - the number of nodes this branch contains
 
 
- 
nodeIterator
public Iterator<Node> nodeIterator()
Description copied from interface:BranchReturns an iterator through the content nodes of this branch- Specified by:
 nodeIteratorin interfaceBranch- Overrides:
 nodeIteratorin classAbstractElement- Returns:
 - an iterator through the content nodes of this branch
 
 
- 
attributes
public List<Attribute> attributes()
Description copied from interface:ElementReturns 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.- Specified by:
 attributesin interfaceElement- Overrides:
 attributesin classAbstractElement- Returns:
 - the attributes that this element contains as a 
List 
 
- 
setAttributes
public void setAttributes(List<Attribute> attributes)
Description copied from interface:ElementSets the attributes that this element contains- Parameters:
 attributes- DOCUMENT ME!
 
- 
attributeIterator
public Iterator<Attribute> attributeIterator()
Description copied from interface:ElementDOCUMENT ME!- Specified by:
 attributeIteratorin interfaceElement- Overrides:
 attributeIteratorin classAbstractElement- Returns:
 - an iterator over the attributes of this element
 
 
- 
attribute
public Attribute attribute(int index)
Description copied from interface:ElementReturns the attribute at the specified indexGets the- Specified by:
 attributein interfaceElement- Overrides:
 attributein classAbstractElement- 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
 
 
- 
attributeCount
public int attributeCount()
Description copied from interface:ElementDOCUMENT ME!- Specified by:
 attributeCountin interfaceElement- Overrides:
 attributeCountin classAbstractElement- Returns:
 - the number of attributes this element contains
 
 
- 
attribute
public Attribute attribute(String name)
Description copied from interface:ElementReturns the attribute with the given name- Specified by:
 attributein interfaceElement- Overrides:
 attributein classAbstractElement- 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
public Attribute attribute(QName qName)
Description copied from interface:ElementDOCUMENT ME!- Specified by:
 attributein interfaceElement- Overrides:
 attributein classAbstractElement- Parameters:
 qName- is the fully qualified name- Returns:
 - the attribute for the given fully qualified name or null if it could not be found.
 
 
- 
attribute
public Attribute attribute(String name, Namespace namespace)
- Overrides:
 attributein classAbstractElement
 
- 
add
public void add(Attribute attribute)
Description copied from interface:ElementAdds 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.- Specified by:
 addin interfaceElement- Overrides:
 addin classAbstractElement- Parameters:
 attribute- is the attribute to be added
 
- 
remove
public boolean remove(Attribute attribute)
Description copied from interface:ElementRemoves the givenAttributefrom this element.- Specified by:
 removein interfaceElement- Overrides:
 removein classAbstractElement- Parameters:
 attribute- is the attribute to be removed- Returns:
 - true if the attribute was removed
 
 
- 
addNewNode
protected void addNewNode(Node node)
Description copied from class:AbstractElementLike addNode() but does not require a parent check- Overrides:
 addNewNodein classAbstractElement- Parameters:
 node- DOCUMENT ME!
 
- 
removeNode
protected boolean removeNode(Node node)
- Overrides:
 removeNodein classAbstractElement
 
- 
contentList
protected List<Node> contentList()
Description copied from class:AbstractBranchDOCUMENT ME!- Specified by:
 contentListin classAbstractBranch- Returns:
 - the internal List used to manage the content
 
 
- 
attributeList
protected List<Attribute> attributeList()
Description copied from class:AbstractElementDOCUMENT ME!- Specified by:
 attributeListin classAbstractElement- Returns:
 - the internal List used to store attributes or creates one if one is not available
 
 
- 
attributeList
protected List<Attribute> attributeList(int size)
Description copied from class:AbstractElementDOCUMENT ME!- Specified by:
 attributeListin classAbstractElement- Parameters:
 size- DOCUMENT ME!- Returns:
 - the internal List used to store attributes or creates one with the specified size if one is not available
 
 
- 
getDocumentFactory
protected DocumentFactory getDocumentFactory()
- Overrides:
 getDocumentFactoryin classAbstractElement
 
 - 
 
 -