|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Element
interface 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()
or Node.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 | |
void |
add(Attribute attribute)
Adds the given Attribute to this element. |
void |
add(CDATA cdata)
Adds the given CDATA to this element. |
void |
add(Entity entity)
Adds the given Entity to this element. |
void |
add(Namespace namespace)
Adds the given Namespace to this element. |
void |
add(Text text)
Adds the given Text to this element. |
Element |
addAttribute(QName qName,
java.lang.String value)
Adds the attribute value of the given fully qualified name. |
Element |
addAttribute(java.lang.String name,
java.lang.String value)
Adds the attribute value of the given local name. |
Element |
addCDATA(java.lang.String cdata)
Adds a new CDATA node with the given text to this element. |
Element |
addComment(java.lang.String comment)
Adds a new Comment node with the given text to this element. |
Element |
addEntity(java.lang.String name,
java.lang.String text)
Adds a new Entity node with the given name and text
to this element and returns a reference to the new node. |
java.util.List |
additionalNamespaces()
Returns any additional namespaces declarations for this element other than namespace returned via the getNamespace() method. |
Element |
addNamespace(java.lang.String prefix,
java.lang.String uri)
Adds a namespace to this element for use by its child content |
Element |
addProcessingInstruction(java.lang.String target,
java.util.Map data)
Adds a processing instruction for the given target |
Element |
addProcessingInstruction(java.lang.String target,
java.lang.String text)
Adds a processing instruction for the given target |
Element |
addText(java.lang.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. |
Attribute |
attribute(int index)
Returns the attribute at the specified indexGets the |
Attribute |
attribute(QName qName)
|
Attribute |
attribute(java.lang.String name)
Returns the attribute with the given name |
int |
attributeCount()
|
java.util.Iterator |
attributeIterator()
|
java.util.List |
attributes()
Returns the Attribute instances this element contains as
a backed List so that the attributes may be modified directly
using the List interface. |
java.lang.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. |
java.lang.String |
attributeValue(QName qName,
java.lang.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. |
java.lang.String |
attributeValue(java.lang.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. |
java.lang.String |
attributeValue(java.lang.String name,
java.lang.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. |
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. |
Element |
createCopy(QName qName)
Creates a deep copy of this element with the given fully qualified name. |
Element |
createCopy(java.lang.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. |
java.util.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(java.lang.String name)
Returns the first element for the given local name and any namespace. |
java.util.Iterator |
elementIterator()
Returns an iterator over all this elements child elements. |
java.util.Iterator |
elementIterator(QName qName)
Returns an iterator over the elements contained in this element which match the given fully qualified name. |
java.util.Iterator |
elementIterator(java.lang.String name)
Returns an iterator over the elements contained in this element which match the given local name and any namespace. |
java.util.List |
elements()
Returns the elements contained in this element. |
java.util.List |
elements(QName qName)
Returns the elements contained in this element with the given fully qualified name. |
java.util.List |
elements(java.lang.String name)
Returns the elements contained in this element with the given local name and any namespace. |
java.lang.String |
elementText(QName qname)
|
java.lang.String |
elementText(java.lang.String name)
|
java.lang.String |
elementTextTrim(QName qname)
|
java.lang.String |
elementTextTrim(java.lang.String name)
|
java.lang.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 getText() |
Namespace |
getNamespace()
Returns the Namespace of this element if one exists
otherwise Namespace.NO_NAMESPACE is returned. |
Namespace |
getNamespaceForPrefix(java.lang.String prefix)
Returns the Namespace which is mapped to the given
prefix or null if it could not be found. |
Namespace |
getNamespaceForURI(java.lang.String uri)
Returns the Namespace which is mapped to the given
URI or null if it could not be found. |
java.lang.String |
getNamespacePrefix()
Returns the namespace prefix of this element if one exists otherwise an empty String is returned. |
java.util.List |
getNamespacesForURI(java.lang.String uri)
Returns the all namespaces which are mapped to the given URI or an empty list if no such namespaces could be found. |
java.lang.String |
getNamespaceURI()
Returns the URI mapped to the namespace of this element if one exists otherwise an empty String is returned. |
QName |
getQName()
Returns the QName of this element which represents
the local name, the qualified name and the Namespace . |
QName |
getQName(java.lang.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. |
java.lang.String |
getQualifiedName()
Returns the fully qualified name of this element. |
java.lang.String |
getStringValue()
Returns the XPath string-value of this node. |
java.lang.String |
getText()
Returns the text value of this element without recursing through child elements. |
java.lang.String |
getTextTrim()
|
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. |
boolean |
isRootElement()
|
boolean |
isTextOnly()
Returns true if this Element has text only content. |
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(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(Text text)
Removes the given Text if the node is
an immediate child of this element. |
void |
setAttributes(java.util.List attributes)
Sets the attributes that this element contains |
void |
setAttributeValue(QName qName,
java.lang.String value)
Deprecated. As of version 0.5. Please use addAttribute(QName,String) instead.
WILL BE REMOVED IN dom4j-1.6 !! |
void |
setAttributeValue(java.lang.String name,
java.lang.String value)
Deprecated. As of version 0.5. Please use addAttribute(String,String) instead.
WILL BE REMOVED IN dom4j-1.6 !! |
void |
setData(java.lang.Object data)
Sets the data value of this element if this element supports data binding or calls Node.setText(java.lang.String) if it doesn't |
void |
setQName(QName qname)
Sets the QName of this element which represents
the local name, the qualified name and the Namespace . |
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 |
public QName getQName()
Returns the QName
of this element which represents
the local name, the qualified name and the Namespace
.
QName
associated with this elementpublic void setQName(QName qname)
Sets the QName
of this element which represents
the local name, the qualified name and the Namespace
.
qname
- is the QName
to be associated with this elementpublic Namespace getNamespace()
Returns the Namespace
of this element if one exists
otherwise Namespace.NO_NAMESPACE
is returned.
Namespace
associated with this elementpublic QName getQName(java.lang.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.
QName
for the given qualified namepublic Namespace getNamespaceForPrefix(java.lang.String prefix)
Returns the Namespace
which is mapped to the given
prefix or null if it could not be found.
Namespace
associated with the given prefixpublic Namespace getNamespaceForURI(java.lang.String uri)
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.
Namespace
associated with the given URIpublic java.util.List getNamespacesForURI(java.lang.String uri)
Returns the all namespaces which are mapped to the given URI or an empty list if no such namespaces could be found.
public java.lang.String getNamespacePrefix()
Returns the namespace prefix of this element if one exists
otherwise an empty String
is returned.
Namespace
of this element
or an empty String
public java.lang.String getNamespaceURI()
Returns the URI mapped to the namespace of this element
if one exists otherwise an empty String
is returned.
Namespace
of this element
or an empty String
public java.lang.String getQualifiedName()
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.
public java.util.List additionalNamespaces()
Returns any additional namespaces declarations for this element
other than namespace returned via the 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.
public java.util.List 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.
public Element addAttribute(java.lang.String name, java.lang.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.
name
- is the name of the attribute whose value is to be added
or updatedvalue
- is the attribute's value
Element
instance.public Element addAttribute(QName qName, java.lang.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.
qName
- is the fully qualified name of the attribute
whose value is to be added or updatedvalue
- is the attribute's value
Element
instance.public Element addComment(java.lang.String comment)
Comment
node with the given text to this element.
comment
- is the text for the Comment
node.
Element
instance.public Element addCDATA(java.lang.String cdata)
CDATA
node with the given text to this element.
cdata
- is the text for the CDATA
node.
Element
instance.public Element addEntity(java.lang.String name, java.lang.String text)
Entity
node with the given name and text
to this element and returns a reference to the new node.
name
- is the name for the Entity
node.text
- is the text for the Entity
node.
Element
instance.public Element addNamespace(java.lang.String prefix, java.lang.String uri)
prefix
- is the prefix to use, which should not be null or blankuri
- is the namespace URI
Element
instance.public Element addProcessingInstruction(java.lang.String target, java.lang.String text)
target
- is the target of the processing instructiontext
- is the textual data (key/value pairs) of the processing instruction
Element
instance.public Element addProcessingInstruction(java.lang.String target, java.util.Map data)
target
- is the target of the processing instructiondata
- is a Map of the key / value pairs of the processing instruction
Element
instance.public Element addText(java.lang.String text)
Text
node with the given text to this element.
text
- is the text for the Text
node.
Element
instance.public void add(Attribute attribute)
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.
attribute
- is the attribute to be addedpublic void add(CDATA cdata)
CDATA
to this element.
If the given node already has a parent defined then an
IllegalAddException
will be thrown.
cdata
- is the CDATA to be addedpublic void add(Entity entity)
Entity
to this element.
If the given node already has a parent defined then an
IllegalAddException
will be thrown.
entity
- is the entity to be addedpublic void add(Text text)
Text
to this element.
If the given node already has a parent defined then an
IllegalAddException
will be thrown.
text
- is the text to be addedpublic void add(Namespace namespace)
Namespace
to this element.
If the given node already has a parent defined then an
IllegalAddException
will be thrown.
namespace
- is the namespace to be addedpublic boolean remove(Attribute attribute)
Attribute
from this element.
attribute
- is the attribute to be removed
public boolean remove(CDATA cdata)
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.
cdata
- is the CDATA to be removed
public boolean remove(Entity entity)
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.
entity
- is the entity to be removed
public boolean remove(Namespace namespace)
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.
namespace
- is the namespace to be removed
public boolean remove(Text text)
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.
text
- is the text to be removed
public java.lang.String getText()
Text
, CDATA
and
Entity
nodes that this element contains
and appends the text values together.
getText
in interface Node
public java.lang.String getTextTrim()
public java.lang.String getStringValue()
Text
, CDATA
, Entity
and Element
nodes
all appended together.
getStringValue
in interface Node
public java.lang.Object getData()
getText()
public void setData(java.lang.Object data)
Node.setText(java.lang.String)
if it doesn't
public java.util.List attributes()
Returns the Attribute
instances this element contains as
a backed List
so that the attributes may be modified directly
using the List
interface.
The List
is backed by the Element
so that
changes to the list are reflected in the element and vice versa.
List
public void setAttributes(java.util.List attributes)
public int attributeCount()
public java.util.Iterator attributeIterator()
public Attribute attribute(int index)
public Attribute attribute(java.lang.String name)
public Attribute attribute(QName qName)
qName
- is the fully qualified name
public java.lang.String attributeValue(java.lang.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.
name
- is the name of the attribute value to be returnd
public java.lang.String attributeValue(java.lang.String name, java.lang.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.
name
- is the name of the attribute value to be returnddefaultValue
- is the default value to be returned if the
attribute has no value defined.
public java.lang.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.
qName
- is the fully qualified name
public java.lang.String attributeValue(QName qName, java.lang.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.
qName
- is the fully qualified namedefaultValue
- is the default value to be returned if the
attribute has no value defined.
public void setAttributeValue(java.lang.String name, java.lang.String value)
addAttribute(String,String)
instead.
WILL BE REMOVED IN dom4j-1.6 !!
Sets the attribute value of the given local name.
name
- is the name of the attribute whose value is to be added
or updatedvalue
- is the attribute's valuepublic void setAttributeValue(QName qName, java.lang.String value)
addAttribute(QName,String)
instead.
WILL BE REMOVED IN dom4j-1.6 !!
Sets the attribute value of the given fully qualified name.
qName
- is the fully qualified name of the attribute
whose value is to be added or updatedvalue
- is the attribute's valuepublic Element element(java.lang.String name)
public Element element(QName qName)
qName
- is the fully qualified name to search for
public java.util.List 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.
public java.util.List elements(java.lang.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.
public java.util.List 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.
qName
- is the fully qualified name to search for
public java.util.Iterator elementIterator()
public java.util.Iterator elementIterator(java.lang.String name)
public java.util.Iterator elementIterator(QName qName)
qName
- is the fully qualified name to search for
public boolean isRootElement()
public boolean hasMixedContent()
Returns true if this Element
has mixed content.
Mixed content means that an element contains both textual data and
child elements.
public boolean isTextOnly()
Returns true if this Element
has text only content.
public void appendAttributes(Element element)
Collection.addAll(java.util.Collection)
method.
element
- is the element whose attributes will be added to me.public 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.
public Element createCopy(java.lang.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.
public 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.
public java.lang.String elementText(java.lang.String name)
public java.lang.String elementText(QName qname)
public java.lang.String elementTextTrim(java.lang.String name)
public java.lang.String elementTextTrim(QName qname)
public Node getXPathResult(int index)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |