Interface Element

官方路径:http://dom4j.sourceforge.net/dom4j-1.6.1/apidocs/org/dom4j/Element.html

org.dom4j 
Interface Element

All Superinterfaces:
BranchCloneableNode
All Known Implementing Classes:
AbstractElement

public interface  Element extends  Branch

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 .

Version:
$Revision: 1.47 $
Author:
James Strachan 

Field Summary
 
Fields inherited from interface org.dom4j.Node
ANY_NODEATTRIBUTE_NODECDATA_SECTION_NODECOMMENT_NODEDOCUMENT_NODEDOCUMENT_TYPE_NODEELEMENT_NODEENTITY_REFERENCE_NODEMAX_NODE_TYPENAMESPACE_NODEPROCESSING_INSTRUCTION_NODETEXT_NODEUNKNOWN_NODE
 
Method Summary
 voidadd(Attribute attribute) 
          Adds the given Attribute to this element. 
 voidadd(CDATA cdata) 
          Adds the given CDATA to this element. 
 voidadd(Entity entity) 
          Adds the given Entity to this element. 
 voidadd(Namespace namespace) 
          Adds the given Namespace to this element. 
 voidadd(Text text) 
          Adds the given Text to this element. 
 ElementaddAttribute(QName qName, String value) 
           Adds the attribute value of the given fully qualified name. 
 ElementaddAttribute(String name, String value) 
           Adds the attribute value of the given local name. 
 ElementaddCDATA(String cdata) 
          Adds a new CDATA node with the given text to this element.
 ElementaddComment(String comment) 
          Adds a new Comment node with the given text to this element.
 ElementaddEntity(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.
 ListadditionalNamespaces() 
           Returns any additional namespaces declarations for this element other than namespace returned via the getNamespace()method. 
 ElementaddNamespace(String prefix, String uri) 
          Adds a namespace to this element for use by its child content
 ElementaddProcessingInstruction(String target, Map data) 
          Adds a processing instruction for the given target
 ElementaddProcessingInstruction(String target, String text) 
          Adds a processing instruction for the given target
 ElementaddText(String text) 
          Adds a new Text node with the given text to this element.
 voidappendAttributes(Element element) 
          Appends the attributes of the given element to me. 
 Attributeattribute(int index) 
          Returns the attribute at the specified indexGets the
 Attributeattribute(QName qName) 
          DOCUMENT ME!
 Attributeattribute(String name) 
          Returns the attribute with the given name
 intattributeCount() 
          DOCUMENT ME!
 IteratorattributeIterator() 
          DOCUMENT ME!
 Listattributes() 
           Returns the Attributeinstances this element contains as a backed Listso that the attributes may be modified directly using the Listinterface. 
 StringattributeValue(QName qName) 
           This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.
 StringattributeValue(QName qName, String defaultValue) 
           This returns the attribute value for the attribute with the given fully qualified name or the default value if there is no such attribute value.
 StringattributeValue(String name) 
           This returns the attribute value for the attribute with the given name and any namespace or null if there is no such attribute or the empty string if the attribute value is empty.
 StringattributeValue(String name, String defaultValue) 
           This returns the attribute value for the attribute with the given name and any namespace or the default value if there is no such attribute value.
 ElementcreateCopy() 
           Creates a deep copy of this element The new element is detached from its parent, and getParent() on the clone will return null.
 ElementcreateCopy(QName qName) 
           Creates a deep copy of this element with the given fully qualified name.
 ElementcreateCopy(String name) 
           Creates a deep copy of this element with the given local name The new element is detached from its parent, and getParent() on the clone will return null.
 ListdeclaredNamespaces() 
           Returns all the namespaces declared by this element. 
 Elementelement(QName qName) 
          Returns the first element for the given fully qualified name.
 Elementelement(String name) 
          Returns the first element for the given local name and any namespace.
 IteratorelementIterator() 
          Returns an iterator over all this elements child elements.
 IteratorelementIterator(QName qName) 
          Returns an iterator over the elements contained in this element which match the given fully qualified name.
 IteratorelementIterator(String name) 
          Returns an iterator over the elements contained in this element which match the given local name and any namespace.
 Listelements() 
           Returns the elements contained in this element. 
 Listelements(QName qName) 
           Returns the elements contained in this element with the given fully qualified name. 
 Listelements(String name) 
           Returns the elements contained in this element with the given local name and any namespace. 
 StringelementText(QName qname) 
           
 StringelementText(String name) 
           
 StringelementTextTrim(QName qname) 
           
 StringelementTextTrim(String name) 
           
 ObjectgetData() 
          Accesses the data of this element which may implement data typing bindings such as XML Schema or Java Bean bindings or will return the same value as getText()
 NamespacegetNamespace() 
           Returns the Namespace of this element if one exists otherwise Namespace.NO_NAMESPACE is returned.
 NamespacegetNamespaceForPrefix(String prefix) 
           Returns the Namespace which is mapped to the given prefix or null if it could not be found.
 NamespacegetNamespaceForURI(String uri) 
           Returns the Namespace which is mapped to the given URI or null if it could not be found. 
 StringgetNamespacePrefix() 
           Returns the namespace prefix of this element if one exists otherwise an empty String is returned.
 ListgetNamespacesForURI(String uri) 
           Returns the all namespaces which are mapped to the given URI or an empty list if no such namespaces could be found.
 StringgetNamespaceURI() 
           Returns the URI mapped to the namespace of this element if one exists otherwise an empty String is returned.
 QNamegetQName() 
           Returns the QName of this element which represents the local name, the qualified name and the Namespace.
 QNamegetQName(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.
 StringgetQualifiedName() 
           Returns the fully qualified name of this element. 
 StringgetStringValue() 
          Returns the XPath string-value of this node. 
 StringgetText() 
          Returns the text value of this element without recursing through child elements. 
 StringgetTextTrim() 
          DOCUMENT ME!
 NodegetXPathResult(int index) 
          Returns a node at the given index suitable for an XPath result set. 
 booleanhasMixedContent() 
           Returns true if this Element has mixed content. 
 booleanisRootElement() 
          DOCUMENT ME!
 booleanisTextOnly() 
           Returns true if this Element has text only content.
 booleanremove(Attribute attribute) 
          Removes the given Attribute from this element.
 booleanremove(CDATA cdata) 
          Removes the given CDATA if the node is an immediate child of this element. 
 booleanremove(Entity entity) 
          Removes the given Entity if the node is an immediate child of this element. 
 booleanremove(Namespace namespace) 
          Removes the given Namespace if the node is an immediate child of this element. 
 booleanremove(Text text) 
          Removes the given Text if the node is an immediate child of this element. 
 voidsetAttributes(List attributes) 
          Sets the attributes that this element contains
 voidsetAttributeValue(QName qName, String value) 
          Deprecated. As of version 0.5. Please use addAttribute(QName,String) instead. WILL BE REMOVED IN dom4j-1.6 !!
 voidsetAttributeValue(String name, String value) 
          Deprecated. As of version 0.5. Please use addAttribute(String,String) instead. WILL BE REMOVED IN dom4j-1.6 !!
 voidsetData(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
 voidsetQName(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
addaddaddaddaddElementaddElementaddElementappendContentclearContentcontentelementByIDindexOfnodenodeCountnodeIteratornormalizeprocessingInstructionprocessingInstructionsprocessingInstructionsremoveremoveremoveremoveremoveProcessingInstructionsetContentsetProcessingInstructions
 
Methods inherited from interface org.dom4j.Node
acceptasXMLasXPathResultclonecreateXPathdetachgetDocumentgetNamegetNodeTypegetNodeTypeNamegetParentgetPathgetPathgetUniquePathgetUniquePathhasContentisReadOnlymatchesnumberValueOfselectNodesselectNodesselectNodesselectObjectselectSingleNodesetDocumentsetNamesetParentsetTextsupportsParentvalueOfwrite
 

Method Detail

getQName

public QName getQName()

Returns the QName of this element which represents the local name, the qualified name and the Namespace.

Returns:
the  QName associated with this element

setQName

public void setQName(QName qname)

Sets the QName of this element which represents the local name, the qualified name and the Namespace.

Parameters:
qname - is the  QName to be associated with this element

getNamespace

public Namespace getNamespace()

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

Returns:
the  Namespace associated with this element

getQName

public 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.

Parameters:
qualifiedName - DOCUMENT ME!
Returns:
the  QName for the given qualified name

getNamespaceForPrefix

public Namespace getNamespaceForPrefix(String prefix)

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

Parameters:
prefix - DOCUMENT ME!
Returns:
the  Namespace associated with the given prefix

getNamespaceForURI

public Namespace getNamespaceForURI(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.

Parameters:
uri - DOCUMENT ME!
Returns:
the  Namespace associated with the given URI

getNamespacesForURI

public 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.

Parameters:
uri - DOCUMENT ME!
Returns:
the namespaces associated with the given URI
Since:
1.5

getNamespacePrefix

public String getNamespacePrefix()

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

Returns:
the prefix of the  Namespace of this element or an empty  String

getNamespaceURI

public String getNamespaceURI()

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

Returns:
the URI for the  Namespace of this element or an empty  String

getQualifiedName

public 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.

Returns:
the fully qualified name of the element.

additionalNamespaces

public 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.

Returns:
a list of any additional namespace declarations.

declaredNamespaces

public 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.

Returns:
a list of namespaces declared for this element.

addAttribute

public Element addAttribute(String name,
                            String value)

Adds the attribute value of the given local name. If an attribute already exists for the given name it will be replaced. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the given name.

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

addAttribute

public Element addAttribute(QName qName,
                            String value)

Adds the attribute value of the given fully qualified name. If an attribute already exists for the given name it will be replaced. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the given name.

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

addComment

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

Parameters:
comment - is the text for the  Comment node.
Returns:
this  Element instance.

addCDATA

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

Parameters:
cdata - is the text for the  CDATA node.
Returns:
this  Element instance.

addEntity

public 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.

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)
Adds a namespace to this element for use by its child content

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

addProcessingInstruction

public Element addProcessingInstruction(String target,
                                        String text)
Adds a processing instruction for the given target

Parameters:
target - is the target of the processing instruction
text - is the textual data (key/value pairs) of the processing instruction
Returns:
this  Element instance.

addProcessingInstruction

public Element addProcessingInstruction(String target,
                                        Map data)
Adds a processing instruction for the given target

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)
Adds a new  Text node with the given text to this element.

Parameters:
text - is the text for the  Text node.
Returns:
this  Element instance.

add

public void add(Attribute attribute)
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.

Parameters:
attribute - is the attribute to be added

add

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

Parameters:
cdata - is the CDATA to be added

add

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

Parameters:
entity - is the entity to be added

add

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

Parameters:
text - is the text to be added

add

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

Parameters:
namespace - is the namespace to be added

remove

public boolean remove(Attribute attribute)
Removes the given  Attribute from this element.

Parameters:
attribute - is the attribute to be removed
Returns:
true if the attribute was removed

remove

public boolean remove(CDATA cdata)
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.

Parameters:
cdata - is the CDATA to be removed
Returns:
true if the cdata was removed

remove

public boolean remove(Entity entity)
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.

Parameters:
entity - is the entity to be removed
Returns:
true if the entity was removed

remove

public boolean remove(Namespace namespace)
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.

Parameters:
namespace - is the namespace to be removed
Returns:
true if the namespace was removed

remove

public boolean remove(Text text)
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.

Parameters:
text - is the text to be removed
Returns:
true if the text was removed

getText

public String getText()
Returns the text value of this element without recursing through child elements. This method iterates through all  Text, CDATA and  Entitynodes that this element contains and appends the text values together.

Specified by:
getText in interface  Node
Returns:
the textual content of this Element. Child elements are not navigated. This method does not return null;

getTextTrim

public String getTextTrim()
DOCUMENT ME!

Returns:
the trimmed text value where whitespace is trimmed and normalised into single spaces. This method does not return null.

getStringValue

public String getStringValue()
Returns the XPath string-value of this node. The behaviour of this method is defined in the  XPath specification . This method returns the string-value of all the contained  Text, CDATA, Entityand  Element nodes all appended together.

Specified by:
getStringValue in interface  Node
Returns:
the text from all the child Text and Element nodes appended together.

getData

public 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()

Returns:
DOCUMENT ME!

setData

public void setData(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

Parameters:
data - DOCUMENT ME!

attributes

public List attributes()

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.

Returns:
the attributes that this element contains as a  List

setAttributes

public void setAttributes(List attributes)
Sets the attributes that this element contains

Parameters:
attributes - DOCUMENT ME!

attributeCount

public int attributeCount()
DOCUMENT ME!

Returns:
the number of attributes this element contains

attributeIterator

public Iterator attributeIterator()
DOCUMENT ME!

Returns:
an iterator over the attributes of this element

attribute

public Attribute attribute(int index)
Returns the attribute at the specified indexGets the

Parameters:
index - DOCUMENT ME!
Returns:
the attribute at the specified index where index >= 0 and index < number of attributes or throws an IndexOutOfBoundsException if the index is not within the allowable range

attribute

public Attribute attribute(String name)
Returns the attribute with the given name

Parameters:
name - DOCUMENT ME!
Returns:
the attribute for the given local name in any namespace. If there are more than one attributes with the given local name in different namespaces then the first one is returned.

attribute

public Attribute attribute(QName qName)
DOCUMENT ME!

Parameters:
qName - is the fully qualified name
Returns:
the attribute for the given fully qualified name or null if it could not be found.

attributeValue

public String attributeValue(String name)

This returns the attribute value for the attribute with the given name and any namespace or null if there is no such attribute or the empty string if the attribute value is empty.

Parameters:
name - is the name of the attribute value to be returnd
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)

This returns the attribute value for the attribute with the given name and any namespace or the default value if there is no such attribute value.

Parameters:
name - is the name of the attribute value to be 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)

This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.

Parameters:
qName - is the fully qualified name
Returns:
the value of the attribute, null if the attribute does not exist or the empty string

attributeValue

public String attributeValue(QName qName,
                             String defaultValue)

This returns the attribute value for the attribute with the given fully qualified name or the default value if there is no such attribute value.

Parameters:
qName - is the fully qualified 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 !!

Sets the attribute value of the given local name.

Parameters:
name - is the name of the attribute whose value is to be added or updated
value - is the attribute's value

setAttributeValue

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

Sets the attribute value of the given fully qualified name.

Parameters:
qName - is the fully qualified name of the attribute whose value is to be added or updated
value - is the attribute's value

element

public Element element(String name)
Returns the first element for the given local name and any namespace.

Parameters:
name - DOCUMENT ME!
Returns:
the first element with the given local name

element

public Element element(QName qName)
Returns the first element for the given fully qualified name.

Parameters:
qName - is the fully qualified name to search for
Returns:
the first element with the given fully qualified name

elements

public 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.

Returns:
a list of all the elements in this element.

elements

public List elements(String name)

Returns the elements contained in this element with the given local name and any namespace. If no elements are found then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.

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

elements

public 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.

Parameters:
qName - is the fully qualified name to search for
Returns:
a list of all the elements in this element for the given fully qualified name.

elementIterator

public Iterator elementIterator()
Returns an iterator over all this elements child elements.

Returns:
an iterator over the contained elements

elementIterator

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

Parameters:
name - DOCUMENT ME!
Returns:
an iterator over the contained elements matching the given local name

elementIterator

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

Parameters:
qName - is the fully qualified name to search for
Returns:
an iterator over the contained elements matching the given fully qualified name

isRootElement

public boolean isRootElement()
DOCUMENT ME!

Returns:
true if this element is the root element of a document and this element supports the parent relationship else false.

hasMixedContent

public boolean hasMixedContent()

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

Returns:
true if this element contains mixed content.

isTextOnly

public boolean isTextOnly()

Returns true if this Element has text only content.

Returns:
true if this element is empty or only contains text content.

appendAttributes

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

Parameters:
element - is the element whose attributes will be added to me.

createCopy

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.

Returns:
a new deep copy Element

createCopy

public Element createCopy(String name)

Creates a deep copy of this element with the given local name The new element is detached from its parent, and getParent() on the clone will return null.

Parameters:
name - DOCUMENT ME!
Returns:
a new deep copy Element

createCopy

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.

Parameters:
qName - DOCUMENT ME!
Returns:
a new deep copy Element

elementText

public String elementText(String name)

elementText

public String elementText(QName qname)

elementTextTrim

public String elementTextTrim(String name)

elementTextTrim

public String elementTextTrim(QName qname)

getXPathResult

public Node getXPathResult(int index)
Returns a node at the given index suitable for an XPath result set. This means the resulting Node will either be null or it will support the parent relationship.

Parameters:
index - DOCUMENT ME!
Returns:
the Node for the given index which will support the parent relationship or null if there is not a node at the given index.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值