org.dom4j.tree
Class AbstractElement

java.lang.Object
  extended byorg.dom4j.tree.AbstractNode
      extended byorg.dom4j.tree.AbstractBranch
          extended byorg.dom4j.tree.AbstractElement
All Implemented Interfaces:
Branch, Cloneable, Element, Node, Serializable
Direct Known Subclasses:
BaseElement, DefaultElement

public abstract class AbstractElement
extends AbstractBranch
implements Element

AbstractElement is an abstract base class for tree implementors to use for implementation inheritence.

Version:
$Revision: 1.80 $
Author:
James Strachan
See Also:
Serialized Form

Field Summary
protected static Iterator EMPTY_ITERATOR
           
protected static List EMPTY_LIST
           
protected static boolean USE_STRINGVALUE_SEPARATOR
           
protected static boolean 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
AbstractElement()
           
 
Method Summary
 void accept(Visitor visitor)
           accept method is the Visitor Pattern method.
 void add(Attribute attribute)
          Adds the given Attribute to this element.
 void add(CDATA cdata)
          Adds the given CDATA to this element.
 void add(Comment comment)
          Adds the given Comment to this branch.
 void add(Element element)
          Adds the given Element to this branch.
 void add(Entity entity)
          Adds the given Entity to this element.
 void add(Namespace namespace)
          Adds the given Namespace to this element.
 void add(Node node)
          Adds the given Node or throws IllegalAddException if the given node is not of a valid type.
 void add(ProcessingInstruction pi)
          Adds the given ProcessingInstruction to this branch.
 void add(Text text)
          Adds the given Text to this element.
 Element addAttribute(QName qName, String value)
           Adds the attribute value of the given fully qualified name.
 Element addAttribute(String name, String value)
           Adds the attribute value of the given local name.
 Element addCDATA(String cdata)
          Adds a new CDATA node with the given text to this element.
 Element addComment(String comment)
          Adds a new Comment node with the given text to this element.
 Element addElement(String name)
          Adds a new Element node with the given name to this branch and returns a reference to the new node.
 Element addEntity(String name, String text)
          Adds a new Entity node with the given name and text to this element and returns a reference to the new node.
 List additionalNamespaces()
           Returns any additional namespaces declarations for this element other than namespace returned via the getNamespace()method.
 List additionalNamespaces(String defaultNamespaceURI)
           
 Element addNamespace(String prefix, String uri)
          Adds a namespace to this element for use by its child content
protected  void addNewNode(int index, Node node)
           
protected  void addNewNode(Node node)
          Like addNode() but does not require a parent check
protected  void addNode(int index, Node node)
           
protected  void addNode(Node node)
           
 Element addProcessingInstruction(String target, Map data)
          Adds a processing instruction for the given target
 Element addProcessingInstruction(String target, String data)
          Adds a processing instruction for the given target
 Element addText(String text)
          Adds a new Text node with the given text to this element.
 void appendAttributes(Element element)
          Appends the attributes of the given element to me.
 String asXML()
           asXML returns the textual XML representation of this node.
 Attribute attribute(int index)
          Returns the attribute at the specified indexGets the
 Attribute attribute(QName qName)
          DOCUMENT ME!
 Attribute attribute(String name)
          Returns the attribute with the given name
 Attribute attribute(String name, Namespace namespace)
           
 int attributeCount()
          DOCUMENT ME!
 Iterator attributeIterator()
          DOCUMENT ME!
protected abstract  List attributeList()
          DOCUMENT ME!
protected abstract  List attributeList(int attributeCount)
          DOCUMENT ME!
 List attributes()
           Returns the Attributeinstances this element contains as a backed Listso that the attributes may be modified directly using the Listinterface.
 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.
 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.
 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.
 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.
protected  void childAdded(Node node)
          Called when a new child node is added to create any parent relationships
protected  void childRemoved(Node node)
          Called when a child node has been removed to allow any parent relationships to be deleted or events to be fired.
protected  List createAttributeList()
          A Factory Method pattern which creates a List implementation used to store attributes
protected  List createAttributeList(int size)
          A Factory Method pattern which creates a List implementation used to store attributes
 Element createCopy()
           This returns a deep clone of this element.
 Element createCopy(QName qName)
           Creates a deep copy of this element with the given fully qualified name.
 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.
protected  Element createElement(QName qName)
           
protected  Element createElement(String name)
           
protected  Iterator createSingleIterator(Object result)
           
 List declaredNamespaces()
           Returns all the namespaces declared by this element.
 Element element(QName qName)
          Returns the first element for the given fully qualified name.
 Element element(String name)
          Returns the first element for the given local name and any namespace.
 Element element(String name, Namespace namespace)
           
 Iterator elementIterator()
          Returns an iterator over all this elements child elements.
 Iterator elementIterator(QName qName)
          Returns an iterator over the elements contained in this element which match the given fully qualified name.
 Iterator elementIterator(String name)
          Returns an iterator over the elements contained in this element which match the given local name and any namespace.
 Iterator elementIterator(String name, Namespace ns)
           
 List elements()
           Returns the elements contained in this element.
 List elements(QName qName)
           Returns the elements contained in this element with the given fully qualified name.
 List elements(String name)
           Returns the elements contained in this element with the given local name and any namespace.
 List elements(String name, Namespace namespace)
           
 String elementText(QName qName)
           
 String elementText(String name)
           
 String elementTextTrim(QName qName)
           
 String elementTextTrim(String name)
           
 void ensureAttributesCapacity(int minCapacity)
          Ensures that the list of attributes has the given size
 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 as AbstractBranch.getText()
protected  DocumentFactory getDocumentFactory()
           
 String getName()
           getName returns the name of this node.
 Namespace getNamespace()
           Returns the Namespace of this element if one exists otherwise Namespace.NO_NAMESPACE is returned.
 Namespace getNamespaceForPrefix(String prefix)
           Returns the Namespace which is mapped to the given prefix or null if it could not be found.
 Namespace getNamespaceForURI(String uri)
           Returns the Namespace which is mapped to the given URI or null if it could not be found.
 String getNamespacePrefix()
           Returns the namespace prefix of this element if one exists otherwise an empty String is returned.
 List 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.
 String getNamespaceURI()
           Returns the URI mapped to the namespace of this element if one exists otherwise an empty String is returned.
 short getNodeType()
          Returns the code according to the type of node.
 String getPath(Element context)
          Returns the relative XPath expression which will return a node set containing the given node such as a/b/@c.
 QName getQName(String qualifiedName)
           Returns the QName for 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.
 String getQualifiedName()
           Returns the fully qualified name of this element.
 String getStringValue()
          Returns the XPath string-value of this node.
 String getUniquePath(Element context)
           Returns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node.
 String getXPathNameStep()
          Returns the XPath expression to match this Elements name which is getQualifiedName() if there is a namespace prefix defined or if no namespace is present then it is getName() or if a namespace is defined with no prefix then the expression is [name()='X'] where X = getName().
 Node getXPathResult(int index)
          Returns a node at the given index suitable for an XPath result set.
 boolean hasMixedContent()
           Returns true if this Element has mixed content.
 int indexOf(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.
 boolean isRootElement()
          DOCUMENT ME!
 boolean isTextOnly()
           Returns true if this Element has text only content.
 Node node(int index)
          Returns the Node at the specified index position.
 int nodeCount()
          Returns the number of Node instances that this branch contains.
 Iterator nodeIterator()
          Returns an iterator through the content nodes of this branch
 void normalize()
          Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
 ProcessingInstruction processingInstruction(String target)
          DOCUMENT ME!
 List processingInstructions()
           Returns a list of all the processing instructions in this branch.
 List processingInstructions(String target)
           Returns a list of the processing instructions for the given target.
 boolean remove(Attribute attribute)
          Removes the given Attribute from this element.
 boolean remove(CDATA cdata)
          Removes the given CDATA if the node is an immediate child of this element.
 boolean remove(Comment comment)
          Removes the given Comment if the node is an immediate child of this branch.
 boolean remove(Element element)
          Removes the given Element if the node is an immediate child of this branch.
 boolean remove(Entity entity)
          Removes the given Entity if the node is an immediate child of this element.
 boolean remove(Namespace namespace)
          Removes the given Namespace if the node is an immediate child of this element.
 boolean remove(Node node)
          Removes the given Node if the node is an immediate child of this branch.
 boolean remove(ProcessingInstruction pi)
          Removes the given ProcessingInstruction if the node is an immediate child of this branch.
 boolean remove(Text text)
          Removes the given Text if the node is an immediate child of this element.
protected  boolean removeNode(Node node)
           
 boolean removeProcessingInstruction(String target)
          Removes the processing instruction for the given target if it exists
 void setAttributes(Attributes attributes, NamespaceStack namespaceStack, boolean noNamespaceAttributes)
          This method provides a more optimal way of setting all the attributes on an Element particularly for use in SAXReader.
 void setAttributeValue(QName qName, String value)
          Deprecated. As of version 0.5. Please use addAttribute(String,String) instead. WILL BE REMOVED IN dom4j-1.6 !!
 void setAttributeValue(String name, String value)
          Deprecated. As of version 0.5. Please use addAttribute(String,String) instead. WILL BE REMOVED IN dom4j-1.6 !!
 void setData(Object data)
          Sets the data value of this element if this element supports data binding or calls setText(java.lang.String)if it doesn't
 void setName(String name)
           Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.
 void setNamespace(Namespace namespace)
           
 void setText(String text)
           Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.
 String toString()
           
 void write(Writer out)
           write writes this node as the default XML notation for this node.
 
Methods inherited from class org.dom4j.tree.AbstractBranch
addElement, addElement, addElement, appendContent, content, contentList, contentRemoved, createContentList, createContentList, createEmptyList, createResultList, createSingleResultList, elementByID, elementID, getContentAsStringValue, getContentAsText, getText, getTextTrim, hasContent, invalidNodeTypeAddException, isReadOnly, setProcessingInstructions
 
Methods inherited from class org.dom4j.tree.AbstractNode
asXPathResult, clone, createPattern, createXPath, createXPathFilter, createXPathResult, detach, getDocument, getNodeTypeName, getParent, getPath, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, setDocument, setParent, supportsParent, valueOf
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.dom4j.Element
getQName, getText, getTextTrim, setAttributes, setQName
 
Methods inherited from interface org.dom4j.Branch
addElement, addElement, appendContent, clearContent, content, elementByID, setContent, setProcessingInstructions
 
Methods inherited from interface org.dom4j.Node
asXPathResult, clone, createXPath, detach, getDocument, getNodeTypeName, getParent, getPath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, setDocument, setParent, supportsParent, valueOf
 

Field Detail

EMPTY_LIST

protected static final List EMPTY_LIST

EMPTY_ITERATOR

protected static final Iterator EMPTY_ITERATOR

VERBOSE_TOSTRING

protected static final boolean VERBOSE_TOSTRING
See Also:
Constant Field Values

USE_STRINGVALUE_SEPARATOR

protected static final boolean USE_STRINGVALUE_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

AbstractElement

public AbstractElement()
Method Detail

getNodeType

public short getNodeType()
Description copied from interface: Node
Returns the code according to the type of node. This makes processing nodes polymorphically much easier as the switch statement can be used instead of multiple if (instanceof) statements.

Specified by:
getNodeType in interface Node
Overrides:
getNodeType in class AbstractNode

isRootElement

public boolean isRootElement()
Description copied from interface: Element
DOCUMENT ME!

Specified by:
isRootElement in interface Element
Returns:
true if this element is the root element of a document and this element supports the parent relationship else false.

setName

public void setName(String name)
Description copied from interface: Node

Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

Specified by:
setName in interface Node
Overrides:
setName in class AbstractNode

setNamespace

public void setNamespace(Namespace namespace)

getXPathNameStep

public String getXPathNameStep()
Returns the XPath expression to match this Elements name which is getQualifiedName() if there is a namespace prefix defined or if no namespace is present then it is getName() or if a namespace is defined with no prefix then the expression is [name()='X'] where X = getName().

Returns:
DOCUMENT ME!

getPath

public String getPath(Element context)
Description copied from interface: Node
Returns the relative XPath expression which will return a node set containing the given node such as a/b/@c. No indexing will be used to restrict the path if multiple elements with the same name occur on the path.

Specified by:
getPath in interface Node
Parameters:
context - is the parent context from which the relative path should start. If the context is null or the context is not an ancestor of this node then the path will be absolute and start from the document and so begin with the '/' character.
Returns:
the XPath expression relative to the given context which will return a nodeset containing at least this node.

getUniquePath

public String getUniquePath(Element context)
Description copied from interface: Node

Returns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node. This method will use the XPath index operator to restrict the path if multiple elements with the same name occur on the path.

Specified by:
getUniquePath in interface Node
Parameters:
context - is the parent context from which the path should start. If the context is null or the context is not an ancestor of this node then the path will start from the document and so begin with the '/' character.
Returns:
the XPath expression relative to the given context which will return a nodeset containing just this node.

asXML

public String asXML()
Description copied from interface: Node

asXML returns the textual XML representation of this node.

Specified by:
asXML in interface Node
Returns:
the XML representation of this node

write

public void write(Writer out)
           throws IOException
Description copied from interface: Node

write writes this node as the default XML notation for this node. If you wish to control the XML output (such as for pretty printing, changing the indentation policy etc.) then please use XMLWriter or its derivations.

Specified by:
write in interface Node
Overrides:
write in class AbstractNode
Throws:
IOException

accept

public void accept(Visitor visitor)

accept method is the Visitor Pattern method.

Specified by:
accept in interface Node
Parameters:
visitor - Visitor is the visitor.

toString

public String toString()

getNamespace

public Namespace getNamespace()
Description copied from interface: Element

Returns the Namespace of this element if one exists otherwise Namespace.NO_NAMESPACE is returned.

Specified by:
getNamespace in interface Element
Returns:
the Namespace associated with this element

getName

public String getName()
Description copied from interface: Node

getName returns the name of this node. This is the XML local name of the element, attribute, entity or processing instruction. For CDATA and Text nodes this method will return null.

Specified by:
getName in interface Node
Overrides:
getName in class AbstractNode

getNamespacePrefix

public String getNamespacePrefix()
Description copied from interface: Element

Returns the namespace prefix of this element if one exists otherwise an empty String is returned.

Specified by:
getNamespacePrefix in interface Element
Returns:
the prefix of the Namespace of this element or an empty String

getNamespaceURI

public String getNamespaceURI()
Description copied from interface: Element

Returns the URI mapped to the namespace of this element if one exists otherwise an empty String is returned.

Specified by:
getNamespaceURI in interface Element
Returns:
the URI for the Namespace of this element or an empty String

getQualifiedName

public String getQualifiedName()
Description copied from interface: Element

Returns the fully qualified name of this element. This will be the same as the value returned from Node.getName()if this element has no namespace attached to this element or an expression of the form

 getNamespacePrefix() + ":" + getName()
 
will be returned.

Specified by:
getQualifiedName in interface Element
Returns:
the fully qualified name of the element.

getData

public Object getData()
Description copied from interface: Element
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 as Element.getText()

Specified by:
getData in interface Element
Returns:
DOCUMENT ME!

setData

public void setData(Object data)
Description copied from interface: Element
Sets the data value of this element if this element supports data binding or calls Node.setText(java.lang.String)if it doesn't

Specified by:
setData in interface Element
Parameters:
data - DOCUMENT ME!

node

public Node node(int index)
Description copied from interface: Branch
Returns the Node at the specified index position.

Specified by:
node in interface Branch
Overrides:
node in class AbstractBranch

indexOf

public int indexOf(Node node)
Description copied from interface: Branch
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.

Specified by:
indexOf in interface Branch
Overrides:
indexOf in class AbstractBranch

nodeCount

public int nodeCount()
Description copied from interface: Branch
Returns the number of Node instances that this branch contains.

Specified by:
nodeCount in interface Branch
Overrides:
nodeCount in class AbstractBranch

nodeIterator

public Iterator nodeIterator()
Description copied from interface: Branch
Returns an iterator through the content nodes of this branch

Specified by:
nodeIterator in interface Branch
Overrides:
nodeIterator in class AbstractBranch

element

public Element element(String name)
Description copied from interface: Element
Returns the first element for the given local name and any namespace.

Specified by:
element in interface Element
Parameters:
name - DOCUMENT ME!
Returns:
the first element with the given local name

element

public Element element(QName qName)
Description copied from interface: Element
Returns the first element for the given fully qualified name.

Specified by:
element in interface Element
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)

elements

public List elements()
Description copied from interface: Element

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.

Specified by:
elements in interface Element
Returns:
a list of all the elements in this element.

elements

public List elements(String name)
Description copied from interface: Element

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.

Specified by:
elements in interface Element
Parameters:
name - DOCUMENT ME!
Returns:
a list of all the elements in this element for the given local name

elements

public List elements(QName qName)
Description copied from interface: Element

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.

Specified by:
elements in interface Element
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.

elements

public List elements(String name,
                     Namespace namespace)

elementIterator

public Iterator elementIterator()
Description copied from interface: Element
Returns an iterator over all this elements child elements.

Specified by:
elementIterator in interface Element
Returns:
an iterator over the contained elements

elementIterator

public Iterator elementIterator(String name)
Description copied from interface: Element
Returns an iterator over the elements contained in this element which match the given local name and any namespace.

Specified by:
elementIterator in interface Element
Parameters:
name - DOCUMENT ME!
Returns:
an iterator over the contained elements matching the given local name

elementIterator

public Iterator elementIterator(QName qName)
Description copied from interface: Element
Returns an iterator over the elements contained in this element which match the given fully qualified name.

Specified by:
elementIterator in interface Element
Parameters:
qName - is the fully qualified name to search for
Returns:
an iterator over the contained elements matching the given fully qualified name

elementIterator

public Iterator elementIterator(String name,
                                Namespace ns)

attributes

public List attributes()
Description copied from interface: Element

Returns the Attributeinstances this element contains as a backed Listso that the attributes may be modified directly using the Listinterface. The List is backed by the Element so that changes to the list are reflected in the element and vice versa.

Specified by:
attributes in interface Element
Returns:
the attributes that this element contains as a List

attributeIterator

public Iterator attributeIterator()
Description copied from interface: Element
DOCUMENT ME!

Specified by:
attributeIterator in interface Element
Returns:
an iterator over the attributes of this element

attribute

public Attribute attribute(int index)
Description copied from interface: Element
Returns the attribute at the specified indexGets the

Specified by:
attribute in interface Element
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: Element
DOCUMENT ME!

Specified by:
attributeCount in interface Element
Returns:
the number of attributes this element contains

attribute

public Attribute attribute(String name)
Description copied from interface: Element
Returns the attribute with the given name

Specified by:
attribute in interface Element
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: Element
DOCUMENT ME!

Specified by:
attribute in interface Element
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)

setAttributes

public void setAttributes(Attributes attributes,
                          NamespaceStack namespaceStack,
                          boolean noNamespaceAttributes)
This method provides a more optimal way of setting all the attributes on an Element particularly for use in SAXReader.

Parameters:
attributes - DOCUMENT ME!
namespaceStack - DOCUMENT ME!
noNamespaceAttributes - DOCUMENT ME!

attributeValue

public String attributeValue(String name)
Description copied from interface: Element

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.

Specified by:
attributeValue in interface Element
Parameters:
name - is the name of the attribute value to be returnd
Returns:
the value of the attribute, null if the attribute does not exist or the empty string

attributeValue

public String attributeValue(QName qName)
Description copied from interface: Element

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.

Specified by:
attributeValue in interface Element
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

public String attributeValue(String name,
                             String defaultValue)
Description copied from interface: Element

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.

Specified by:
attributeValue in interface Element
Parameters:
name - is the name of the attribute value to be returnd
defaultValue - 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

public String attributeValue(QName qName,
                             String defaultValue)
Description copied from interface: Element

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.

Specified by:
attributeValue in interface Element
Parameters:
qName - is the fully qualified name
defaultValue - 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

public void setAttributeValue(String name,
                              String value)
Deprecated. As of version 0.5. Please use addAttribute(String,String) instead. WILL BE REMOVED IN dom4j-1.6 !!

DOCUMENT ME!

Specified by:
setAttributeValue in interface Element
Parameters:
name - DOCUMENT ME!
value - DOCUMENT ME!

setAttributeValue

public void setAttributeValue(QName qName,
                              String value)
Deprecated. As of version 0.5. Please use addAttribute(String,String) instead. WILL BE REMOVED IN dom4j-1.6 !!

DOCUMENT ME!

Specified by:
setAttributeValue in interface Element
Parameters:
qName - DOCUMENT ME!
value - DOCUMENT ME!

add

public void add(Attribute attribute)
Description copied from interface: Element
Adds the given Attribute to this element. If the given node already has a parent defined then an IllegalAddException will 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:
add in interface Element
Parameters:
attribute - is the attribute to be added

remove

public boolean remove(Attribute attribute)
Description copied from interface: Element
Removes the given Attribute from this element.

Specified by:
remove in interface Element
Parameters:
attribute - is the attribute to be removed
Returns:
true if the attribute was removed

processingInstructions

public List processingInstructions()
Description copied from interface: Branch

Returns 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:
processingInstructions in interface Branch
Returns:
a backed list of the processing instructions

processingInstructions

public List processingInstructions(String target)
Description copied from interface: Branch

Returns 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:
processingInstructions in interface Branch
Parameters:
target - DOCUMENT ME!
Returns:
a backed list of the processing instructions

processingInstruction

public ProcessingInstruction processingInstruction(String target)
Description copied from interface: Branch
DOCUMENT ME!

Specified by:
processingInstruction in interface Branch
Parameters:
target - DOCUMENT ME!
Returns:
the processing instruction for the given target

removeProcessingInstruction

public boolean removeProcessingInstruction(String target)
Description copied from interface: Branch
Removes the processing instruction for the given target if it exists

Specified by:
removeProcessingInstruction in interface Branch
Parameters:
target - DOCUMENT ME!
Returns:
true if a processing instruction was removed else false

getXPathResult

public Node getXPathResult(int index)
Description copied from interface: Element
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.

Specified by:
getXPathResult in interface Element
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.

addAttribute

public Element addAttribute(String name,
                            String value)
Description copied from interface: Element

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.

Specified by:
addAttribute in interface Element
Parameters:
name - is the name of the attribute whose value is to be added or updated
value - is the attribute's value
Returns:
this Element instance.

addAttribute

public Element addAttribute(QName qName,
                            String value)
Description copied from interface: Element

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.

Specified by:
addAttribute in interface Element
Parameters:
qName - is the fully qualified name of the attribute whose value is to be added or updated
value - is the attribute's value
Returns:
this Element instance.

addCDATA

public Element addCDATA(String cdata)
Description copied from interface: Element
Adds a new CDATA node with the given text to this element.

Specified by:
addCDATA in interface Element
Parameters:
cdata - is the text for the CDATA node.
Returns:
this Element instance.

addComment

public Element addComment(String comment)
Description copied from interface: Element
Adds a new Comment node with the given text to this element.

Specified by:
addComment in interface Element
Parameters:
comment - is the text for the Comment node.
Returns:
this Element instance.

addElement

public Element addElement(String name)
Description copied from interface: Branch
Adds a new Element node with the given name to this branch and returns a reference to the new node.

Specified by:
addElement in interface Branch
Overrides:
addElement in class AbstractBranch

addEntity

public Element addEntity(String name,
                         String text)
Description copied from interface: Element
Adds a new Entity node with the given name and text to this element and returns a reference to the new node.

Specified by:
addEntity in interface Element
Parameters:
name - is the name for the Entity node.
text - is the text for the Entity node.
Returns:
this Element instance.

addNamespace

public Element addNamespace(String prefix,
                            String uri)
Description copied from interface: Element
Adds a namespace to this element for use by its child content

Specified by:
addNamespace in interface Element
Parameters:
prefix - is the prefix to use, which should not be null or blank
uri - is the namespace URI
Returns:
this Element instance.

addProcessingInstruction

public Element addProcessingInstruction(String target,
                                        String data)
Description copied from interface: Element
Adds a processing instruction for the given target

Specified by:
addProcessingInstruction in interface Element
Parameters:
target - is the target of the processing instruction
data - is the textual data (key/value pairs) of the processing instruction
Returns:
this Element instance.

addProcessingInstruction

public Element addProcessingInstruction(String target,
                                        Map data)
Description copied from interface: Element
Adds a processing instruction for the given target

Specified by:
addProcessingInstruction in interface Element
Parameters:
target - is the target of the processing instruction
data - is a Map of the key / value pairs of the processing instruction
Returns:
this Element instance.

addText

public Element addText(String text)
Description copied from interface: Element
Adds a new Text node with the given text to this element.

Specified by:
addText in interface Element
Parameters:
text - is the text for the Text node.
Returns:
this Element instance.

add

public void add(Node node)
Description copied from interface: Branch
Adds the given Node or throws IllegalAddException if the given node is not of a valid type. This is a polymorphic method which will call the typesafe method for the node type such as add(Element) or add(Comment).

Specified by:
add in interface Branch
Overrides:
add in class AbstractBranch

remove

public boolean remove(Node node)
Description copied from interface: Branch
Removes the given Node if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node.detach()method should be used instead. This is a polymorphic method which will call the typesafe method for the node type such as remove(Element) or remove(Comment).

Specified by:
remove in interface Branch
Overrides:
remove in class AbstractBranch

add

public void add(CDATA cdata)
Description copied from interface: Element
Adds the given CDATA to this element. If the given node already has a parent defined then an IllegalAddException will be thrown.

Specified by:
add in interface Element
Parameters:
cdata - is the CDATA to be added

add

public void add(Comment comment)
Description copied from interface: Branch
Adds the given Comment to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Specified by:
add in interface Branch
Overrides:
add in class AbstractBranch

add

public void add(Element element)
Description copied from interface: Branch
Adds the given Element to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Specified by:
add in interface Branch
Overrides:
add in class AbstractBranch

add

public void add(Entity entity)
Description copied from interface: Element
Adds the given Entity to this element. If the given node already has a parent defined then an IllegalAddException will be thrown.

Specified by:
add in interface Element
Parameters:
entity - is the entity to be added

add

public void add(Namespace namespace)
Description copied from interface: Element
Adds the given Namespace to this element. If the given node already has a parent defined then an IllegalAddException will be thrown.

Specified by:
add in interface Element
Parameters:
namespace - is the namespace to be added

add

public void add(ProcessingInstruction pi)
Description copied from interface: Branch
Adds the given ProcessingInstruction to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Specified by:
add in interface Branch
Overrides:
add in class AbstractBranch

add

public void add(Text text)
Description copied from interface: Element
Adds the given Text to this element. If the given node already has a parent defined then an IllegalAddException will be thrown.

Specified by:
add in interface Element
Parameters:
text - is the text to be added

remove

public boolean remove(CDATA cdata)
Description copied from interface: Element
Removes the given CDATA if the node is an immediate child of this element. If the given node is not an immediate child of this element then the Node.detach()method should be used instead.

Specified by:
remove in interface Element
Parameters:
cdata - is the CDATA to be removed
Returns:
true if the cdata was removed

remove

public boolean remove(Comment comment)
Description copied from interface: Branch
Removes the given Comment if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node.detach()method should be used instead.

Specified by:
remove in interface Branch
Overrides:
remove in class AbstractBranch

remove

public boolean remove(Element element)
Description copied from interface: Branch
Removes the given Element if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node.detach()method should be used instead.

Specified by:
remove in interface Branch
Overrides:
remove in class AbstractBranch

remove

public boolean remove(Entity entity)
Description copied from interface: Element
Removes the given Entity if the node is an immediate child of this element. If the given node is not an immediate child of this element then the Node.detach()method should be used instead.

Specified by:
remove in interface Element
Parameters:
entity - is the entity to be removed
Returns:
true if the entity was removed

remove

public boolean remove(Namespace namespace)
Description copied from interface: Element
Removes the given Namespace if the node is an immediate child of this element. If the given node is not an immediate child of this element then the Node.detach()method should be used instead.

Specified by:
remove in interface Element
Parameters:
namespace - is the namespace to be removed
Returns:
true if the namespace was removed

remove

public boolean remove(ProcessingInstruction pi)
Description copied from interface: Branch
Removes the given ProcessingInstruction if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node.detach()method should be used instead.

Specified by:
remove in interface Branch
Overrides:
remove in class AbstractBranch

remove

public boolean remove(Text text)
Description copied from interface: Element
Removes the given Text if the node is an immediate child of this element. If the given node is not an immediate child of this element then the Node.detach()method should be used instead.

Specified by:
remove in interface Element
Parameters:
text - is the text to be removed
Returns:
true if the text was removed

hasMixedContent

public boolean hasMixedContent()
Description copied from interface: Element

Returns true if this Element has mixed content. Mixed content means that an element contains both textual data and child elements.

Specified by:
hasMixedContent in interface Element
Returns:
true if this element contains mixed content.

isTextOnly

public boolean isTextOnly()
Description copied from interface: Element

Returns true if this Element has text only content.

Specified by:
isTextOnly in interface Element
Returns:
true if this element is empty or only contains text content.

setText

public void setText(String text)
Description copied from interface: Node

Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

Specified by:
setText in interface Node
Overrides:
setText in class AbstractNode

getStringValue

public String getStringValue()
Description copied from interface: Element
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 contained Text,CDATA,Entityand Element nodes all appended together.

Specified by:
getStringValue in interface Element
Overrides:
getStringValue in class AbstractNode

normalize

public void normalize()
Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.

Specified by:
normalize in interface Branch
Since:
DOM Level 2

elementText

public String elementText(String name)
Specified by:
elementText in interface Element

elementText

public String elementText(QName qName)
Specified by:
elementText in interface Element

elementTextTrim

public String elementTextTrim(String name)
Specified by:
elementTextTrim in interface Element

elementTextTrim

public String elementTextTrim(QName qName)
Specified by:
elementTextTrim in interface Element

appendAttributes

public void appendAttributes(Element element)
Description copied from interface: Element
Appends the attributes of the given element to me. This method behaves like the Collection.addAll(java.util.Collection) method.

Specified by:
appendAttributes in interface Element
Parameters:
element - is the element whose attributes will be added to me.

createCopy

public Element createCopy()

This returns a deep clone of this element. The new element is detached from its parent, and getParent() on the clone will return null.

Specified by:
createCopy in interface Element
Returns:
the clone of this element

createCopy

public Element createCopy(String name)
Description copied from interface: Element

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.

Specified by:
createCopy in interface Element
Parameters:
name - DOCUMENT ME!
Returns:
a new deep copy Element

createCopy

public Element createCopy(QName qName)
Description copied from interface: Element

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.

Specified by:
createCopy in interface Element
Parameters:
qName - DOCUMENT ME!
Returns:
a new deep copy Element

getQName

public QName getQName(String qualifiedName)
Description copied from interface: Element

Returns the QName for 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.

Specified by:
getQName in interface Element
Parameters:
qualifiedName - DOCUMENT ME!
Returns:
the QName for the given qualified name

getNamespaceForPrefix

public Namespace getNamespaceForPrefix(String prefix)
Description copied from interface: Element

Returns the Namespace which is mapped to the given prefix or null if it could not be found.

Specified by:
getNamespaceForPrefix in interface Element
Parameters:
prefix - DOCUMENT ME!
Returns:
the Namespace associated with the given prefix

getNamespaceForURI

public Namespace getNamespaceForURI(String uri)
Description copied from interface: Element

Returns the Namespace which is mapped to the given URI or null if it could not be found. If there is more than one Namespace mapped to the URI, which of them will be returned is undetermined.

Specified by:
getNamespaceForURI in interface Element
Parameters:
uri - DOCUMENT ME!
Returns:
the Namespace associated with the given URI

getNamespacesForURI

public List getNamespacesForURI(String uri)
Description copied from interface: Element

Returns the all namespaces which are mapped to the given URI or an empty list if no such namespaces could be found.

Specified by:
getNamespacesForURI in interface Element
Parameters:
uri - DOCUMENT ME!
Returns:
the namespaces associated with the given URI

declaredNamespaces

public List declaredNamespaces()
Description copied from interface: Element

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.

Specified by:
declaredNamespaces in interface Element
Returns:
a list of namespaces declared for this element.

additionalNamespaces

public List additionalNamespaces()
Description copied from interface: Element

Returns any additional namespaces declarations for this element other than namespace returned via the Element.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:
additionalNamespaces in interface Element
Returns:
a list of any additional namespace declarations.

additionalNamespaces

public List additionalNamespaces(String defaultNamespaceURI)

ensureAttributesCapacity

public void ensureAttributesCapacity(int minCapacity)
Ensures that the list of attributes has the given size

Parameters:
minCapacity - DOCUMENT ME!

createElement

protected Element createElement(String name)

createElement

protected Element createElement(QName qName)

addNode

protected void addNode(Node node)
Specified by:
addNode in class AbstractBranch

addNode

protected void addNode(int index,
                       Node node)
Specified by:
addNode in class AbstractBranch

addNewNode

protected void addNewNode(Node node)
Like addNode() but does not require a parent check

Parameters:
node - DOCUMENT ME!

addNewNode

protected void addNewNode(int index,
                          Node node)

removeNode

protected boolean removeNode(Node node)
Specified by:
removeNode in class AbstractBranch

childAdded

protected void childAdded(Node node)
Called when a new child node is added to create any parent relationships

Specified by:
childAdded in class AbstractBranch
Parameters:
node - DOCUMENT ME!

childRemoved

protected void childRemoved(Node node)
Description copied from class: AbstractBranch
Called when a child node has been removed to allow any parent relationships to be deleted or events to be fired.

Specified by:
childRemoved in class AbstractBranch
Parameters:
node - DOCUMENT ME!

attributeList

protected abstract List attributeList()
DOCUMENT ME!

Returns:
the internal List used to store attributes or creates one if one is not available

attributeList

protected abstract List attributeList(int attributeCount)
DOCUMENT ME!

Parameters:
attributeCount - 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:
getDocumentFactory in class AbstractNode

createAttributeList

protected List createAttributeList()
A Factory Method pattern which creates a List implementation used to store attributes

Returns:
DOCUMENT ME!

createAttributeList

protected List createAttributeList(int size)
A Factory Method pattern which creates a List implementation used to store attributes

Parameters:
size - DOCUMENT ME!
Returns:
DOCUMENT ME!

createSingleIterator

protected Iterator createSingleIterator(Object result)


Copyright © 2001-2005 MetaStuff Ltd.. All Rights Reserved.