Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jdom
Class Element

    java.lang.Object
      |
      +--org.jdom.Element

public class Element
extends Object
implements Serializable, Cloneable

`Element` defines behavior for an XML element, modeled in Java. Methods allow the user to obtain the value of the element's textual content, obtain its attributes, and get its children.

Version:
  1.0
Author:
  Brett McLaughlin, Jason Hunter, Lucas Gonze, Kevin Regan, Dan Schaffer, Yusuf Goolamabbas
See Also:
  Serialized Form

Field Summary
`protected List` | `additionalNamespaces` Additional ``Namespace`` declarations on this element
`protected List` | `attributes` The attributes of the `Element`
`protected List` | `content` The mixed content of the `Element`
`protected String` | `name` The local name of the `Element`
`protected Namespace` | `namespace` The ``Namespace`` of the `Element`
`protected Object` | `parent` Parent element, document, or null if none

Constructor Summary
`protected` | `Element()` This protected constructor is provided in order to support an Element subclass that wants full control over variable initialization.
`` | `Element(String name)` This will create an `Element` in no ``Namespace``.
`` | `Element(String name, Namespace namespace)` This will create a new `Element` with the supplied (local) name, and define the ``Namespace`` to be used.
`` | `Element(String name, String uri)` This will create a new `Element` with the supplied (local) name, and specifies the URI of the ``Namespace`` the `Element` should be in, resulting it being unprefixed (in the default namespace).
`` | `Element(String name, String prefix, String uri)` This will create a new `Element` with the supplied (local) name, and specifies the prefix and URI of the ``Namespace`` the `Element` should be in.

Method Summary
`Element` | `addAttribute(Attribute attribute)` Deprecated. Deprecated in beta7, use setAttribute(Attribute) instead
`Element` | `addAttribute(String name, String value)` Deprecated. Deprecated in beta7, use setAttribute(Attribute) instead
`Element` | `addContent(CDATA cdata)` This adds a CDATA section as content to this element.
`Element` | `addContent(Comment comment)` This adds a comment as content to this element.
`Element` | `addContent(Element element)` This adds element content to this element.
`Element` | `addContent(EntityRef entity)` This adds entity content to this element.
`Element` | `addContent(ProcessingInstruction pi)` This adds a processing instruction as content to this element.
`Element` | `addContent(String text)` This adds text content to this element.
`void` | `addNamespaceDeclaration(Namespace additionalNamespace)` This will add a namespace declarations to this element.
`Object` | `clone()` This returns a deep clone of this element.
`Element` | `detach()` This detaches the element from its parent, or does nothing if the element has no parent.
`boolean` | `equals(Object ob)` This tests for equality of this `Element` to the supplied `Object`, explicitly using the == operator.
`List` | `getAdditionalNamespaces()` This will return any namespace declarations on this element that exist, excluding the namespace of the element itself, which can be obtained through ``getNamespace()``.
`Attribute` | `getAttribute(String name)` This returns the attribute for this element with the given name and within no namespace.
`Attribute` | `getAttribute(String name, Namespace ns)` This returns the attribute for this element with the given name and within the given Namespace.
`List` | `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.
`String` | `getAttributeValue(String 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.
`String` | `getAttributeValue(String name, Namespace 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.
`Element` | `getChild(String name)` This returns the first child element within this element with the given local name and belonging to no namespace.
`Element` | `getChild(String name, Namespace ns)` This returns the first child element within this element with the given local name and belonging to the given namespace.
`List` | `getChildren()` This returns a `List` of all the child elements nested directly (one level deep) within this element, as `Element` objects.
`List` | `getChildren(String 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.
`List` | `getChildren(String name, Namespace 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.
`String` | `getChildText(String name)` This convenience method returns the textual content of the named child element, or returns an empty `String` ("") if the child has no textual content.
`String` | `getChildText(String name, Namespace ns)` This convenience method returns the textual content of the named child element, or returns null if there's no such child.
`String` | `getChildTextTrim(String name)` This convenience method returns the trimmed textual content of the named child element, or returns null if there's no such child.
`String` | `getChildTextTrim(String name, Namespace ns)` This convenience method returns the trimmed textual content of the named child element, or returns null if there's no such child.
`List` | `getContent()` This returns the full content of the element as a List which may contain objects of type `String`, `Element`, `Comment`, `ProcessingInstruction`, `CDATA`, and `EntityRef`.
`Element` | `getCopy(String name)` Deprecated. Deprecated in beta7, use clone() and setName() instead
`Element` | `getCopy(String name, Namespace ns)` Deprecated. Deprecated in beta7, use clone(), setName(), and setNamespace() instead
`Document` | `getDocument()` This retrieves the owning ``Document`` for this Element, or null if not a currently a member of a ``Document``.
`List` | `getMixedContent()` Deprecated. Deprecated in beta7, use getContent() instead
`String` | `getName()` This returns the (local) name of the `Element`, without any namespace prefix, if one exists.
`Namespace` | `getNamespace()` This will return this `Element`'s ``Namespace``.
`Namespace` | `getNamespace(String prefix)` This returns the Namespace in scope on this element for the given prefix (this involves searching up the tree, so the results depend on the current location of the element).
`String` | `getNamespacePrefix()` This returns the namespace prefix of the `Element`, if one exists.
`String` | `getNamespaceURI()` This returns the URI mapped to this `Element`'s prefix (or the default namespace if no prefix).
`Element` | `getParent()` This will return the parent of this `Element`.
`String` | `getQualifiedName()` This returns the full name of the `Element`, in the form [namespacePrefix]:[localName].
`String` | `getSerializedForm()` Deprecated. Deprecated in beta7, use XMLOutputter.outputString(Element) instead
`String` | `getText()` This returns the textual content directly held under this element.
`String` | `getTextNormalize()` This returns the textual content of this element with all surrounding whitespace removed and internal whitespace normalized to a single space.
`String` | `getTextTrim()` This returns the textual content of this element with all surrounding whitespace removed.
`boolean` | `hasChildren()`
`int` | `hashCode()` This returns the hash code for this `Element`.
`boolean` | `hasMixedContent()` Deprecated. Deprecated in beta7 because hasMixedContent() is of little use and isn't really implemented as mixed content is defined
`boolean` | `isRootElement()` This returns a `boolean` value indicating whether this `Element` is a root `Element` for a JDOM ``Document``.
`boolean` | `removeAttribute(String name)` This removes the attribute with the given name and within no namespace.
`boolean` | `removeAttribute(String name, Namespace ns)` This removes the attribute with the given name and within the given Namespace.
`boolean` | `removeAttribute(String name, String uri)` Deprecated. Deprecated in beta7, use removeAttribute(String, Namespace) instead.
`boolean` | `removeChild(String name)` This removes the first child element (one level deep) with the given local name and belonging to no namespace.
`boolean` | `removeChild(String name, Namespace ns)` This removes the first child element (one level deep) with the given local name and belonging to the given namespace.
`boolean` | `removeChildren()` This removes all child elements.
`boolean` | `removeChildren(String name)` This removes all child elements (one level deep) with the given local name and belonging to no namespace.
`boolean` | `removeChildren(String name, Namespace ns)` This removes all child elements (one level deep) with the given local name and belonging to the given namespace.
`boolean` | `removeContent(CDATA cdata)` This removes the specified `CDATA`.
`boolean` | `removeContent(Comment comment)` This removes the specified `Comment`.
`boolean` | `removeContent(Element element)` This removes the specified `Element`.
`boolean` | `removeContent(EntityRef entity)` This removes the specified `EntityRef`.
`boolean` | `removeContent(ProcessingInstruction pi)` This removes the specified `ProcessingInstruction`.
`void` | `removeNamespaceDeclaration(Namespace additionalNamespace)` This will remove a namespace declarations from this element.
`Element` | `setAttribute(Attribute attribute)` This sets an attribute value for this element.
`Element` | `setAttribute(String name, String value)` This sets an attribute value for this element.
`Element` | `setAttribute(String name, String value, Namespace ns)` This sets an attribute value for this element.
`Element` | `setAttributes(List attributes)` This sets all the attributes for this element to be those in the given `List`; all existing attributes are removed.
`Element` | `setChildren(List children)` This sets the content of the element to be the List of `Element` objects within the supplied `List`.
`Element` | `setContent(List newContent)` This sets the content of the element.
`protected Element` | `setDocument(Document document)` This sets the ``Document`` parent of this element and makes it the root element.
`Element` | `setMixedContent(List mixedContent)` Deprecated. Deprecated in beta7, use setContent(List) instead
`Element` | `setName(String name)` This sets the (local) name of the `Element`.
`Element` | `setNamespace(Namespace namespace)` This sets this `Element`'s ``Namespace``.
`protected Element` | `setParent(Element parent)` This will set the parent of this `Element`.
`Element` | `setText(String text)` This sets the content of the element to be the text given.
`String` | `toString()` This returns a `String` representation of the `Element`, suitable for debugging.

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### name

    protected String name

  The local name of the `Element`

### namespace

    protected transient Namespace namespace

  The ``Namespace`` of the `Element`

### additionalNamespaces

    protected transient List additionalNamespaces

  Additional ``Namespace`` declarations on this element

### parent

    protected Object parent

  Parent element, document, or null if none

### attributes

    protected List attributes

  The attributes of the `Element`

### content

    protected List content

  The mixed content of the `Element`

Constructor Detail

### Element

    protected Element()

  This protected constructor is provided in order to support an Element subclass that wants full control over variable initialization. It intentionally leaves all instance variables null, allowing a lightweight subclass implementation. The subclass is responsible for ensuring all the get and set methods on Element behave as documented.

  When implementing an `Element` subclass which doesn't require full control over variable initialization, be aware that simply calling super() (or letting the compiler add the implicit super() call) will not initialize the instance variables which will cause many of the methods to throw a `NullPointerException`. Therefore, the constructor for these subclasses should call one of the public constructors so variable initialization is handled automatically.

### Element

    public Element(String name,
                   Namespace namespace)

  This will create a new `Element` with the supplied (local) name, and define the ``Namespace`` to be used. If the provided namespace is null, the element will have no namespace.

  Parameters:
    `name` - `String` name of element.

### Element

    public Element(String name)

  This will create an `Element` in no ``Namespace``.

  Parameters:
    `name` - `String` name of element.

### Element

    public Element(String name,
                   String uri)

  This will create a new `Element` with the supplied (local) name, and specifies the URI of the ``Namespace`` the `Element` should be in, resulting it being unprefixed (in the default namespace).

  Parameters:
    `name` - `String` name of element.
    `uri` - `String` URI for `Namespace` element should be in.

### Element

    public Element(String name,
                   String prefix,
                   String uri)

  This will create a new `Element` with the supplied (local) name, and specifies the prefix and URI of the ``Namespace`` the `Element` should be in.

  Parameters:
    `name` - `String` name of element.
    `uri` - `String` URI for `Namespace` element should be in.

Method Detail

### getName

    public String getName()

  This returns the (local) name of the `Element`, without any namespace prefix, if one exists.

  Returns:
    `String` - element name.

### setName

    public Element setName(String name)

  This sets the (local) name of the `Element`.

  Returns:
    `Element` - the element modified.
  Throws:
    IllegalNameException - if the given name is invalid as an Element name.

### getNamespace

    public Namespace getNamespace()

  This will return this `Element`'s ``Namespace``.

  Returns:
    `Namespace` - Namespace object for this `Element`

### setNamespace

    public Element setNamespace(Namespace namespace)

  This sets this `Element`'s ``Namespace``. If the provided namespace is null, the element will have no namespace.

  Returns:
    `Element` - the element modified.

### getNamespacePrefix

    public String getNamespacePrefix()

  This returns the namespace prefix of the `Element`, if one exists. Otherwise, an empty `String` is returned.

  Returns:
    `String` - namespace prefix.

### getNamespaceURI

    public String getNamespaceURI()

  This returns the URI mapped to this `Element`'s prefix (or the default namespace if no prefix). If no mapping is found, an empty `String` is returned.

  Returns:
    `String` - namespace URI for this `Element`.

### getNamespace

    public Namespace getNamespace(String prefix)

  This returns the Namespace in scope on this element for the given prefix (this involves searching up the tree, so the results depend on the current location of the element). It returns null if there is no Namespace in scope with the given prefix at this point in the document.

  Parameters:
    `prefix` - namespace prefix to look up
  Returns:
    `Namespace` - namespace in scope for the given prefix on this `Element`, or null if none.

### getQualifiedName

    public String getQualifiedName()

  This returns the full name of the `Element`, in the form [namespacePrefix]:[localName]. If no namespace prefix exists for the `Element`, simply the local name is returned.

  Returns:
    `String` - full name of element.

### addNamespaceDeclaration

    public void addNamespaceDeclaration(Namespace additionalNamespace)

  This will add a namespace declarations to this element. This should not be used to add the declaration for this element itself; that should be assigned in the construction of the element. Instead, this is for adding namespace declarations on the element not relating directly to itself.

  Parameters:
    `additionalNamespace` - `Namespace` to add.
  Throws:
    IllegalAddException - if the namespace prefix collides with another namespace prefix on the element.

### removeNamespaceDeclaration

    public void removeNamespaceDeclaration(Namespace additionalNamespace)

  This will remove a namespace declarations from this element. This should not be used to remove the declaration for this element itself; that should be handled in the construction of the element. Instead, this is for removing namespace declarations on the element not relating directly to itself. If the declaration is not present, this method does nothing.

  Parameters:
    `additionalNamespace` - `Namespace` to remove.

### getAdditionalNamespaces

    public List getAdditionalNamespaces()

  This will return any namespace declarations on this element that exist, excluding the namespace of the element itself, which can be obtained through ``getNamespace()``. If there are no additional declarations, this returns an empty list. Note, the returned list is not live, for performance reasons.

  Returns:
    `List` - the additional namespace declarations.

### getParent

    public Element getParent()

  This will return the parent of this `Element`. If there is no parent, then this returns `null`. Also note that on its own, this is not 100% sufficient to see if the `Element` is not in use - this should be used in tandem with ``isRootElement()`` to determine this.

  Returns:
    parent of this `Element`.

### setParent

    protected Element setParent(Element parent)

  This will set the parent of this `Element`. The caller is responsible for handling pre-existing parentage.

  Parameters:
    `parent` - `Element` to be new parent.
  Returns:
    `Element` - this `Element` modified.

### detach

    public Element detach()

  This detaches the element from its parent, or does nothing if the element has no parent.

  Returns:
    `Element` - this `Element` modified.

### isRootElement

    public boolean isRootElement()

  This returns a `boolean` value indicating whether this `Element` is a root `Element` for a JDOM ``Document``. This should be used in tandem with ``getParent()`` to determine if an `Element` has no "attachments" to parents.

  Returns:
    `boolean` - whether this is a root element.

### setDocument

    protected Element setDocument(Document document)

  This sets the ``Document`` parent of this element and makes it the root element. The caller is responsible for ensuring the element doesn't have a pre-existing parent.

  Parameters:
    `document` - `Document` parent
  Returns:
    `Document` this `Element` modified

### getDocument

    public Document getDocument()

  This retrieves the owning ``Document`` for this Element, or null if not a currently a member of a ``Document``.

  Returns:
    `Document` owning this Element, or null.

### getText

    public String getText()

  This returns the textual content directly held under this element. This will include all text within this single element, including whitespace and CDATA sections if they exist. It's essentially the concatenation of all String nodes returned by getContent(). The call does not recurse into child elements. If no textual value exists for the element, an empty `String` ("") is returned.

  Returns:
    text content for this element, or empty string if none

### getTextTrim

    public String getTextTrim()

  This returns the textual content of this element with all surrounding whitespace removed. If no textual value exists for the element, or if only whitespace exists, the empty string is returned.

  Returns:
    trimmed text content for this element, or empty string if none

### getTextNormalize

    public String getTextNormalize()

  This returns the textual content of this element with all surrounding whitespace removed and internal whitespace normalized to a single space. If no textual value exists for the element, or if only whitespace exists, the empty string is returned.

  Returns:
    normalized text content for this element, or empty string if none

### getChildText

    public String getChildText(String name)

  This convenience method returns the textual content of the named child element, or returns an empty `String` ("") if the child has no textual content. However, if the child does not exist, `null` is returned.

  Parameters:
    `name` - the name of the child
  Returns:
    text content for the named child, or null if none

### getChildTextTrim

    public String getChildTextTrim(String name)

  This convenience method returns the trimmed textual content of the named child element, or returns null if there's no such child. See ``getTextTrim()`` for details of text trimming.

  Parameters:
    `name` - the name of the child
  Returns:
    trimmed text content for the named child, or null if none

### getChildText

    public String getChildText(String name,
                               Namespace ns)

  This convenience method returns the textual content of the named child element, or returns null if there's no such child.

  Parameters:
    `name` - the name of the child
    `ns` - the namespace of the child
  Returns:
    text content for the named child, or null if none

### getChildTextTrim

    public String getChildTextTrim(String name,
                                   Namespace ns)

  This convenience method returns the trimmed textual content of the named child element, or returns null if there's no such child. See ``getTextTrim()`` for details of text trimming.

  Parameters:
    `name` - the name of the child
    `ns` - the namespace of the child
  Returns:
    trimmed text content for the named child, or null if none

### setText

    public Element setText(String text)

  This sets the content of the element to be the text given. All existing text content and non-text context is removed. If this element should have both textual content and nested elements, use ``setContent(java.util.List)`` instead. Setting a null text value is equivalent to setting an empty string value.

  Parameters:
    `text` - new content for the element
  Returns:
    this element modified

### hasMixedContent

    public boolean hasMixedContent()

  Deprecated. Deprecated in beta7 because hasMixedContent() is of little use and isn't really implemented as mixed content is defined

  This will indicate whether the element has mixed content or not. Mixed content is when an element contains both textual and element data within it. When this evaluates to `true`, ``getMixedContent()`` should be used for getting element data.

  Returns:
    `boolean` - indicating whether there is mixed content (both textual data and elements).

### getContent

    public List getContent()

  This returns the full content of the element as a List which may contain objects of type `String`, `Element`, `Comment`, `ProcessingInstruction`, `CDATA`, and `EntityRef`. The List returned is "live" in document order and modifications to it affect the element's actual contents. Whitespace content is returned in its entirety.

  Returns:
    a `List` containing the mixed content of the element: may contain `String`, ``Element``, ``Comment``, ``ProcessingInstruction``, ``CDATA``, and ``EntityRef`` objects.

### setContent

    public Element setContent(List newContent)

  This sets the content of the element. The passed in List should contain only objects of type `String`, `Element`, `Comment`, `ProcessingInstruction`, `CDATA`, and `EntityRef`. Passing a null or empty List clears the existing content. In event of an exception the original content will be unchanged and the items in the added content will be unaltered.

  Returns:
    this element modified
  Throws:
    IllegalAddException - if the List contains objects of illegal types.

### hasChildren

    public boolean hasChildren()

### getChildren

    public List getChildren()

  This returns a `List` of all the child elements nested directly (one level deep) within this element, as `Element` objects. If this target element has no nested elements, an empty List is returned. The returned list is "live" in document order and changes to it affect the element's actual contents.

  This performs no recursion, so elements nested two levels deep would have to be obtained with:

         Iterator itr = currentElement.getChildren().iterator();
         while (itr.hasNext()) {
           Element oneLevelDeep = (Element)nestedElements.next();
           List twoLevelsDeep = oneLevelDeep.getChildren();
           // Do something with these children
         }

  Returns:
    list of child `Element` objects for this element

### setChildren

    public Element setChildren(List children)

  This sets the content of the element to be the List of `Element` objects within the supplied `List`. All existing element and non-element content of the element is removed. In event of an exception the children may be partially added.

  Parameters:
    `children` - `List` of `Element` objects to add
  Returns:
    this element modified

### getChildren

    public List getChildren(String 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. If this target element has no nested elements with the given name outside a namespace, an empty List is returned. The returned list is "live" in document order and changes to it affect the element's actual contents.

  Please see the notes for ``getChildren()`` for a code example.

  Parameters:
    `name` - local name for the children to match
  Returns:
    all matching child elements

### getChildren

    public List getChildren(String name,
                            Namespace 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. If this target element has no nested elements with the given name in the given Namespace, an empty List is returned. The returned list is "live" in document order and changes to it affect the element's actual contents.

  Please see the notes for ``getChildren()`` for a code example.

  Parameters:
    `name` - local name for the children to match
    `ns` - `Namespace` to search within
  Returns:
    all matching child elements

### getChild

    public Element getChild(String name,
                            Namespace ns)

  This returns the first child element within this element with the given local name and belonging to the given namespace. If no elements exist for the specified name and namespace, null is returned.

  Parameters:
    `name` - local name of child element to match
    `ns` - `Namespace` to search within
  Returns:
    the first matching child element, or null if not found

### getChild

    public Element getChild(String name)

  This returns the first child element within this element with the given local name and belonging to no namespace. If no elements exist for the specified name and namespace, null is returned.

  Parameters:
    `name` - local name of child element to match
  Returns:
    the first matching child element, or null if not found

### addContent

    public Element addContent(String text)

  This adds text content to this element. It does not replace the existing content as does `setText()`.

  Parameters:
    `text` - `String` to add
  Returns:
    this element modified

### addContent

    public Element addContent(Element element)

  This adds element content to this element.

  Parameters:
    `element` - `Element` to add
  Returns:
    this element modified
  Throws:
    IllegalAddException - if the element you're attempting to add already has a parent element, or if you're attempting to add it as a descendent of itself (which would result in a recursive element definition!).

### addContent

    public Element addContent(ProcessingInstruction pi)

  This adds a processing instruction as content to this element.

  Parameters:
    `pi` - `ProcessingInstruction` to add
  Returns:
    this element modified
  Throws:
    IllegalAddException - if the given processing instruction, `pi`, already has a parent.

### addContent

    public Element addContent(EntityRef entity)

  This adds entity content to this element.

  Parameters:
    `entity` - `EntityRef` to add
  Returns:
    this element modified
  Throws:
    IllegalAddException - if the given EntityRef already has a parent.

### addContent

    public Element addContent(CDATA cdata)

  This adds a CDATA section as content to this element.

  Parameters:
    `cdata` - `CDATA` to add
  Returns:
    this element modified

### addContent

    public Element addContent(Comment comment)

  This adds a comment as content to this element.

  Parameters:
    `comment` - `Comment` to add
  Returns:
    this element modified
  Throws:
    IllegalAddException - if the given Comment already has a parent.

### removeChild

    public boolean removeChild(String name)

  This removes the first child element (one level deep) with the given local name and belonging to no namespace. Returns true if a child was removed.

  Parameters:
    `name` - the name of child elements to remove
  Returns:
    whether deletion occurred

### removeChild

    public boolean removeChild(String name,
                               Namespace ns)

  This removes the first child element (one level deep) with the given local name and belonging to the given namespace. Returns true if a child was removed.

  Parameters:
    `name` - the name of child element to remove
    `ns` - `Namespace` to search within
  Returns:
    whether deletion occurred

### removeChildren

    public boolean removeChildren(String name)

  This removes all child elements (one level deep) with the given local name and belonging to no namespace. Returns true if any were removed.

  Parameters:
    `name` - the name of child elements to remove
  Returns:
    whether deletion occurred

### removeChildren

    public boolean removeChildren(String name,
                                  Namespace ns)

  This removes all child elements (one level deep) with the given local name and belonging to the given namespace. Returns true if any were removed.

  Parameters:
    `name` - the name of child elements to remove
    `ns` - `Namespace` to search within
  Returns:
    whether deletion occurred

### removeChildren

    public boolean removeChildren()

  This removes all child elements. Returns true if any were removed.

  Returns:
    whether deletion occurred

### getAttributes

    public List 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. The returned list is "live" and changes to it affect the element's actual attributes.

  Returns:
    attributes for the element

### getAttribute

    public Attribute getAttribute(String name)

  This returns the attribute for this element with the given name and within no namespace.

  Parameters:
    `name` - name of the attribute to return
  Returns:
    attribute for the element

### getAttribute

    public Attribute getAttribute(String name,
                                  Namespace ns)

  This returns the attribute for this element with the given name and within the given Namespace.

  Parameters:
    `name` - name of the attribute to return
    `ns` - `Namespace` to search within
  Returns:
    attribute for the element

### getAttributeValue

    public String getAttributeValue(String 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.

  Parameters:
    `name` - name of the attribute whose value to be returned
  Returns:
    the named attribute's value, or null if no such attribute

### getAttributeValue

    public String getAttributeValue(String name,
                                    Namespace 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.

  Parameters:
    `name` - name of the attribute whose valud is to be returned
    `ns` - `Namespace` to search within
  Returns:
    the named attribute's value, or null if no such attribute

### setAttributes

    public Element setAttributes(List attributes)

  This sets all the attributes for this element to be those in the given `List`; all existing attributes are removed.

  Parameters:
    `attributes` - `List` of attributes to set
  Returns:
    this element modified

### setAttribute

    public Element setAttribute(String name,
                                String value)

  This sets an attribute value for this element. Any existing attribute with the same name and namespace URI is removed.

  Parameters:
    `name` - name of the attribute to set
    `value` - value of the attribute to set
  Returns:
    this element modified

### setAttribute

    public Element setAttribute(String name,
                                String value,
                                Namespace ns)

  This sets an attribute value for this element. Any existing attribute with the same name and namespace URI is removed.

  Parameters:
    `name` - name of the attribute to set
    `value` - value of the attribute to set
    `ns` - namespace of the attribute to set
  Returns:
    this element modified

### setAttribute

    public Element setAttribute(Attribute attribute)

  This sets an attribute value for this element. Any existing attribute with the same name and namespace URI is removed.

  Parameters:
    `attribute` - `Attribute` to set
  Returns:
    this element modified
  Throws:
    IllegalAddException - if the attribute being added already has a parent or if the attribute namespace prefix collides with another namespace prefix on the element.

### addAttribute

    public Element addAttribute(String name,
                                String value)

  Deprecated. Deprecated in beta7, use setAttribute(Attribute) instead

  This adds an attribute to this element with the given name and value. To add attributes in namespaces using addAttribute(Attribute).

  Parameters:
    `name` - name of the attribute to add
    `value` - value of the attribute to add
  Returns:
    this element modified

### removeAttribute

    public boolean removeAttribute(String name,
                                   String uri)

  Deprecated. Deprecated in beta7, use removeAttribute(String, Namespace) instead.

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

  Parameters:
    `name` - name of attribute to remove
    `uri` - namespace URI of attribute to remove
  Returns:
    whether the attribute was removed

### removeAttribute

    public boolean removeAttribute(String name)

  This removes the attribute with the given name and within no namespace. If no such attribute exists, this method does nothing.

  Parameters:
    `name` - name of attribute to remove
  Returns:
    whether the attribute was removed

### removeAttribute

    public boolean removeAttribute(String name,
                                   Namespace ns)

  This removes the attribute with the given name and within the given Namespace. If no such attribute exists, this method does nothing.

  Parameters:
    `name` - name of attribute to remove
    `ns` - namespace URI of attribute to remove
  Returns:
    whether the attribute was removed

### toString

    public String toString()

  This returns a `String` representation of the `Element`, suitable for debugging. If the XML representation of the `Element` is desired, `XMLOutputter.outputString(Element)` should be used.

  Overrides:
    toString in class Object
  Returns:
    `String` - information about the `Element`

### equals

    public final boolean equals(Object ob)

  This tests for equality of this `Element` to the supplied `Object`, explicitly using the == operator.

  Overrides:
    equals in class Object
  Parameters:
    `ob` - `Object` to compare to
  Returns:
    whether the elements are equal

### hashCode

    public final int hashCode()

  This returns the hash code for this `Element`.

  Overrides:
    hashCode in class Object
  Returns:
    inherited hash code

### clone

    public Object clone()

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

  Overrides:
    clone in class Object
  Returns:
    the clone of this element

### removeContent

    public boolean removeContent(Element element)

  This removes the specified `Element`. If the specified `Element` is not a child of this `Element`, this method does nothing.

  Parameters:
    `child` - `Element` to delete
  Returns:
    whether deletion occurred

### removeContent

    public boolean removeContent(ProcessingInstruction pi)

  This removes the specified `ProcessingInstruction`. If the specified `ProcessingInstruction` is not a child of this `Element`, this method does nothing.

  Parameters:
    `child` - `ProcessingInstruction` to delete
  Returns:
    whether deletion occurred

### removeContent

    public boolean removeContent(Comment comment)

  This removes the specified `Comment`. If the specified `Comment` is not a child of this `Element`, this method does nothing.

  Parameters:
    `comment` - `Comment` to delete
  Returns:
    whether deletion occurred

### removeContent

    public boolean removeContent(CDATA cdata)

  This removes the specified `CDATA`. If the specified `CDATA` is not a child of this `Element`, this method does nothing.

  Parameters:
    `cdata` - `CDATA` to delete
  Returns:
    whether deletion occurred

### removeContent

    public boolean removeContent(EntityRef entity)

  This removes the specified `EntityRef`. If the specified `EntityRef` is not a child of this `Element`, this method does nothing.

  Parameters:
    `child` - `EntityRef` to delete
  Returns:
    whether deletion occurred

### getCopy

    public Element getCopy(String name,
                           Namespace ns)

  Deprecated. Deprecated in beta7, use clone(), setName(), and setNamespace() instead

  This creates a copy of this `Element`, with the new name specified, and in the specified ``Namespace``.

  Parameters:
    `name` - `String` name of new `Element` copy.
    `ns` - `Namespace` to put copy in.
  Returns:
    `Element` copy of this `Element`.

### getCopy

    public Element getCopy(String name)

  Deprecated. Deprecated in beta7, use clone() and setName() instead

  This creates a copy of this `Element`, with the new name specified, and in no namespace.

  Parameters:
    `name` - `String` name of new `Element` copy.

### addAttribute

    public Element addAttribute(Attribute attribute)

  Deprecated. Deprecated in beta7, use setAttribute(Attribute) instead

  This adds an attribute to this element. Any existing attribute with the same name and namespace URI is removed. (TODO: Code the replacement logic.)

  Parameters:
    `attribute` - `Attribute` to add
  Returns:
    this element modified
  Throws:
    IllegalAddException - if the given attribute already exists within this element.

### getSerializedForm

    public final String getSerializedForm()

  Deprecated. Deprecated in beta7, use XMLOutputter.outputString(Element) instead

  This will return the `Element` in XML format, usable in an XML document.

  Returns:
    `String` - the serialized form of the `Element`.
  Throws:
    RuntimeException - always! This method is not yet implemented. It is also deprecated as of beta 7.

### getMixedContent

    public List getMixedContent()

  Deprecated. Deprecated in beta7, use getContent() instead

  This returns the full content of the element as a List which may contain objects of type `String`, `Element`, `Comment`, `ProcessingInstruction`, `CDATA`, and `EntityRef`. When there is technically no mixed content and all contents are of the same type, then all objects returned in the List will be of the same type. The List returned is "live" in document order and modifications to it affect the element's actual contents. Whitespace content is returned in its entirety.

  Returns:
    a `List` containing the mixed content of the element: may contain `String`, ``Element``, ``Comment``, ``ProcessingInstruction``, ``CDATA``, and ``EntityRef`` objects.

### setMixedContent

    public Element setMixedContent(List mixedContent)

  Deprecated. Deprecated in beta7, use setContent(List) instead

  This sets the content of the element. The passed in List should contain only objects of type `String`, `Element`, `Comment`, `ProcessingInstruction`, `CDATA`, and `EntityRef`. Passing a null or empty List clears the existing content. In event of an exception the original content will be unchanged and the items in the added content will be unaltered.

  Returns:
    this element modified
  Throws:
    IllegalAddException - if the List contains objects of illegal types.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001 Jason Hunter, Brett McLaughlin. All Rights Reserved.