Top Description Fields Constructors Methods
org.jdom

public Class Element

extends Content
implements Parent
Class Inheritance
All Implemented Interfaces
org.jdom.Parent, java.io.Serializable, java.lang.Cloneable
Imports
java.io.*, java.util.*, org.jdom.filter.*

An XML element. Methods allow the user to get and manipulate its child elements and content, directly access the element's textual content, manipulate its attributes, and manage namespaces.
Authors
Brett McLaughlin, Jason Hunter, Lucas Gonze, Kevin Regan, Dan Schaffer, Yusuf Goolamabbas, Kent C. Johnson, Jools Enticknap, Alex Rosen, Bradley S. Huffman, Victor Toni
Version
$Revision: 1.159 $, $Date: 2007/11/14 05:02:08 $

Field Summary

Modifier and TypeField and Description
protected transient List<E>
additionalNamespaces

Additional namespace declarations to store on this element; useful during output

pack-priv AttributeList
attributes

The attributes of the element.

pack-priv ContentList
content

The content of the element.

private static final String
private static final int
protected String
name

The local name of the element

protected transient Namespace
namespace

The namespace of the element

Inherited from org.jdom.Content:
parent

Constructor Summary

AccessConstructor and Description
protected
Element()

This protected constructor is provided in order to support an Element subclass that wants full control over variable initialization.

public
Element(final String
local name of the element
name
,
final Namespace
namespace for the element
namespace
)

Creates a new element with the supplied (local) name and namespace.

public
Element(final String
local name of the element
name
)

Create a new element with the supplied (local) name and no namespace.

public
Element(final String
name of the element
name
,
final String
namespace URI for the element
uri
)

Creates a new element with the supplied (local) name and a namespace given by a URI.

public
Element(final String
local name of the element
name
,
final String
namespace prefix
prefix
,
final String
namespace URI for the element
uri
)

Creates a new element with the supplied (local) name and a namespace given by the supplied prefix and URI combination.

Method Summary

Modifier and TypeMethod and Description
public Element

Returns:

this element modified
addContent
(final String
String to add
str
)

This adds text content to this element.

public Element

Returns:

the element on which the method was called
addContent
(final Content
child to append to end of content list
child
)

Appends the child to the end of the element's content list.

public Element

Returns:

the element on which the method was called
addContent
(final Collection<E>
Collection of content to append
newContent
)

Appends all children in the given collection to the end of the content list.

public Element

Returns:

the parent on which the method was called
addContent
(final int
location for adding the collection
index
,
final Content
child to insert
child
)

Inserts the child into the content list at the given index.

public Element

Returns:

the parent on which the method was called
addContent
(final int
location for adding the collection
index
,
final Collection<E>
Collection of content to insert
newContent
)

Inserts the content in a collection into the content list at the given index.

public void
addNamespaceDeclaration(final Namespace
namespace to add
additionalNamespace
)

Adds a namespace declarations to this element.

public Object

Returns:

the clone of this element
clone
()

Overrides org.jdom.Content.clone.

Implements org.jdom.Parent.clone.

This returns a deep clone of this element.

public List<E>
cloneContent()

Implements org.jdom.Parent.cloneContent.

Returns a list containing detached clones of this parent's content list.
public List<E>

Returns:

a List of the additional namespace declarations
getAdditionalNamespaces
()

Returns a list of the additional namespace declarations on this element.

public Attribute

Returns:

attribute for the element
getAttribute
(final String
name of the attribute to return
name
)

This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.

public Attribute

Returns:

attribute for the element
getAttribute
(final String
name of the attribute to return
name
,
final Namespace
Namespace to search within
ns
)

This returns the attribute for this element with the given name and within the given Namespace, or null if no such attribute exists.

public List<E>

Returns:

attributes for the element
getAttributes
()

This returns the complete set of attributes for this element, as a List of Attribute objects in no particular order, or an empty list if there are none.

public String

Returns:

the named attribute's value, or null if no such attribute
getAttributeValue
(final String
name of the attribute whose value to be returned
name
)

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

public String

Returns:

the named attribute's value, or the default if no such attribute
getAttributeValue
(final String
name of the attribute whose value to be returned
name
,
final String
a default value to return if the attribute does not exist
def
)

This returns the attribute value for the attribute with the given name and within no namespace, or the passed-in default if there is no such attribute.

public String

Returns:

the named attribute's value, or null if no such attribute
getAttributeValue
(final String
name of the attribute whose valud is to be returned
name
,
final Namespace
Namespace to search within
ns
)

This returns the attribute value for the attribute with the given name and within the given Namespace, null if there is no such attribute, and the empty string if the attribute value is empty.

public String

Returns:

the named attribute's value, or the default if no such attribute
getAttributeValue
(final String
name of the attribute whose valud is to be returned
name
,
final Namespace
Namespace to search within
ns
,
final String
a default value to return if the attribute does not exist
def
)

This returns the attribute value for the attribute with the given name and within the given Namespace, or the passed-in default if there is no such attribute.

public Element

Returns:

the first matching child element, or null if not found
getChild
(final String
local name of child element to match
name
,
final Namespace
Namespace to search within
ns
)

This returns the first child element within this element with the given local name and belonging to the given namespace.

public Element

Returns:

the first matching child element, or null if not found
getChild
(final String
local name of child element to match
name
)

This returns the first child element within this element with the given local name and belonging to no namespace.

public List<E>

Returns:

list of child Element objects for this element
getChildren
()

This returns a List of all the child elements nested directly (one level deep) within this element, as Element objects.

public List<E>

Returns:

all matching child elements
getChildren
(final String
local name for the children to match
name
)

This returns a List of all the child elements nested directly (one level deep) within this element with the given local name and belonging to no namespace, returned as Element objects.

public List<E>

Returns:

all matching child elements
getChildren
(final String
local name for the children to match
name
,
final Namespace
Namespace to search within
ns
)

This returns a List of all the child elements nested directly (one level deep) within this element with the given local name and belonging to the given Namespace, returned as Element objects.

public String

Returns:

text content for the named child, or null if no such child
getChildText
(final String
the name of the child
name
)

Returns the textual content of the named child element, or null if there's no such child.

public String

Returns:

text content for the named child, or null if no such child
getChildText
(final String
the name of the child
name
,
final Namespace
the namespace of the child
ns
)

Returns the textual content of the named child element, or null if there's no such child.

public String

Returns:

normalized text content for the named child, or null if no such child
getChildTextNormalize
(final String
the name of the child
name
)

Returns the normalized textual content of the named child element, or null if there's no such child.

public String

Returns:

normalized text content for the named child, or null if no such child
getChildTextNormalize
(final String
the name of the child
name
,
final Namespace
the namespace of the child
ns
)

Returns the normalized textual content of the named child element, or null if there's no such child.

public String

Returns:

trimmed text content for the named child, or null if no such child
getChildTextTrim
(final String
the name of the child
name
)

Returns the trimmed textual content of the named child element, or null if there's no such child.

public String

Returns:

trimmed text content for the named child, or null if no such child
getChildTextTrim
(final String
the name of the child
name
,
final Namespace
the namespace of the child
ns
)

Returns the trimmed textual content of the named child element, or null if there's no such child.

public List<E>

Returns:

a List containing the mixed content of the element: may contain Text, Element, Comment, ProcessingInstruction, CDATA, and EntityRef objects.
getContent
()

Implements org.jdom.Parent.getContent.

This returns the full content of the element as a List which may contain objects of type Text, Element, Comment, ProcessingInstruction, CDATA, and EntityRef.
public List<E>

Returns:

List - filtered Element content
getContent
(final Filter
Filter to apply
filter
)

Implements org.jdom.Parent.getContent.

Return a filter view of this Element's content.
public Content
getContent(final int
location of desired child
index
)

Implements org.jdom.Parent.getContent.

Returns the child at the given index.
public int
getContentSize()

Implements org.jdom.Parent.getContentSize.

Returns the number of children in this parent's content list.
public Iterator<E>

Returns:

an iterator to walk descendants
getDescendants
()

Implements org.jdom.Parent.getDescendants.

Returns an iterator that walks over all descendants in document order.
public Iterator<E>

Returns:

an iterator to walk descendants within a filter
getDescendants
(final Filter
filter to select which descendants to see
filter
)

Implements org.jdom.Parent.getDescendants.

Returns an iterator that walks over all descendants in document order applying the Filter to return only elements that match the filter rule.
public String

Returns:

local element name
getName
()

Returns the (local) name of the element (without any namespace prefix).

public Namespace

Returns:

the element's namespace
getNamespace
()

Returns the element's Namespace.

public Namespace

Returns:

the Namespace for this prefix at this location, or null if none
getNamespace
(final String
namespace prefix to look up
prefix
)

Returns the Namespace corresponding to the given prefix in scope for this element.

public String

Returns:

the namespace prefix
getNamespacePrefix
()

Returns the namespace prefix of the element or an empty string if none exists.

public String

Returns:

the namespace URI for this element
getNamespaceURI
()

Returns the namespace URI mapped to this element's prefix (or the in-scope default namespace URI if no prefix).

public String

Returns:

qualified name of the element (including namespace prefix)
getQualifiedName
()

Returns the full name of the element, in the form [namespacePrefix]:[localName].

public String

Returns:

text content for this element, or empty string if none
getText
()

Returns the textual content directly held under this element as a string.

public String

Returns:

normalized text content for this element, or empty string if none
getTextNormalize
()

Returns the textual content of this element with all surrounding whitespace removed and internal whitespace normalized to a single space.

public String

Returns:

trimmed text content for this element, or empty string if none
getTextTrim
()

Returns the textual content of this element with all surrounding whitespace removed.

public String

Returns:

a concatentation of all text node descendants
getValue
()

Implements abstract org.jdom.Content.getValue.

Returns the XPath 1.0 string value of this element, which is the complete, ordered content of all text node descendants of this element (i.e. the text that's left after all references are resolved and all other markup is stripped out.)
public int
indexOf(final Content
child to search for
child
)

Implements org.jdom.Parent.indexOf.

Returns the index of the supplied child in the content list, or -1 if not a child of this parent.
public boolean

Returns:

true if this element is the ancestor of the supplied element
isAncestor
(final Element
Element to check against
element
)

Determines if this element is the ancestor of another element.

public boolean

Returns:

whether this is a root element
isRootElement
()

Returns whether this element is a root element.

private void
public boolean

Returns:

whether the attribute was removed
removeAttribute
(final String
name of attribute to remove
name
)

This removes the attribute with the given name and within no namespace.

public boolean

Returns:

whether the attribute was removed
removeAttribute
(final String
name of attribute to remove
name
,
final Namespace
namespace URI of attribute to remove
ns
)

This removes the attribute with the given name and within the given Namespace.

public boolean

Returns:

whether the attribute was removed
removeAttribute
(final Attribute
Reference to the attribute to be removed.
attribute
)

This removes the supplied Attribute should it exist.

public boolean

Returns:

whether deletion occurred
removeChild
(final String
the name of child elements to remove
name
)

This removes the first child element (one level deep) with the given local name and belonging to no namespace.

public boolean

Returns:

whether deletion occurred
removeChild
(final String
the name of child element to remove
name
,
final Namespace
Namespace to search within
ns
)

This removes the first child element (one level deep) with the given local name and belonging to the given namespace.

public boolean

Returns:

whether deletion occurred
removeChildren
(final String
the name of child elements to remove
name
)

This removes all child elements (one level deep) with the given local name and belonging to no namespace.

public boolean

Returns:

whether deletion occurred
removeChildren
(final String
the name of child elements to remove
name
,
final Namespace
Namespace to search within
ns
)

This removes all child elements (one level deep) with the given local name and belonging to the given namespace.

public List<E>

Returns:

list of the old children detached from this parent
removeContent
()

Implements org.jdom.Parent.removeContent.

Removes all child content from this parent.
public List<E>

Returns:

list of the old children detached from this parent
removeContent
(final Filter
filter to select which content to remove
filter
)

Implements org.jdom.Parent.removeContent.

Remove all child content from this parent matching the supplied filter.
public boolean
removeContent(final Content
child to remove
child
)

Implements org.jdom.Parent.removeContent.

Removes a single child node from the content list.
public Content
removeContent(final int
index of child to remove
index
)

Implements org.jdom.Parent.removeContent.

Removes and returns the child at the given index, or returns null if there's no such child.
public void
removeNamespaceDeclaration(final Namespace
namespace to remove
additionalNamespace
)

Removes an additional namespace declarations from this element.

public Element

Returns:

this element modified
setAttribute
(final String
name of the attribute to set
name
,
final String
value of the attribute to set
value
)

This sets an attribute value for this element.

public Element

Returns:

this element modified
setAttribute
(final String
name of the attribute to set
name
,
final String
value of the attribute to set
value
,
final Namespace
namespace of the attribute to set
ns
)

This sets an attribute value for this element.

public Element

Returns:

this element modified
setAttribute
(final Attribute
Attribute to set
attribute
)

This sets an attribute value for this element.

public Element

Returns:

this element modified
setAttributes
(final Collection<E>
Collection of attributes to set
newAttributes
)

This sets the attributes of the element.

public Element
setAttributes(final List<E> newAttributes)

This sets the attributes of the element.

public Element

Returns:

this element modified
setContent
(final Collection<E>
Collection of content to set
newContent
)

This sets the content of the element.

public Element

Returns:

element on which this method was invoked
setContent
(final int
- index of child to replace.
index
,
final Content
- child to add.
child
)

Replace the current child the given index with the supplied child.

public Parent

Returns:

object on which this method was invoked
setContent
(final int
- index of child to replace.
index
,
final Collection<E>
- Collection of content to replace child.
newContent
)

Replace the child at the given index whith the supplied collection.

public Element

Returns:

the parent on which the method was called
setContent
(final Content
new content to replace existing content
child
)

Set this element's content to be the supplied child.

public Element

Returns:

the target element
setName
(final String
the new (local) name of the element
name
)

Sets the (local) name of the element.

public Element

Returns:

the target element
setNamespace
(Namespace
the new namespace
namespace
)

Sets the element's Namespace.

public Element

Returns:

the target element
setText
(final String
new text content for the element
text
)

Sets the content of the element to be the text given.

public String

Returns:

String - information about the Element
toString
()

Overrides java.lang.Object.toString.

This returns a String representation of the Element, suitable for debugging.

private void
Inherited from org.jdom.Content:
detachequalsgetDocumentgetParentgetParentElementhashCodesetParent