|
|||||||||
| Home >> All >> org >> [ jdom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.jdom
Class Element

java.lang.Objectorg.jdom.Content
org.jdom.Element
- All Implemented Interfaces:
- java.lang.Cloneable, Parent, java.io.Serializable
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.
- Version:
- $Revision: 1.152 $, $Date: 2004/09/03 06:35:39 $
| Field Summary | |
protected java.util.List |
additionalNamespaces
Additional namespace declarations to store on this element; useful during output |
(package private) AttributeList |
attributes
The attributes of the element. |
(package private) ContentList |
content
The content of the element. |
private static java.lang.String |
CVS_ID
|
private static int |
INITIAL_ARRAY_SIZE
|
protected java.lang.String |
name
The local name of the element |
protected Namespace |
namespace
The namespace of the element |
| Fields inherited from class org.jdom.Content |
parent |
| Constructor Summary | |
protected |
Element()
This protected constructor is provided in order to support an Element subclass that wants full control over variable initialization. |
|
Element(java.lang.String name)
Create a new element with the supplied (local) name and no namespace. |
|
Element(java.lang.String name,
Namespace namespace)
Creates a new element with the supplied (local) name and namespace. |
|
Element(java.lang.String name,
java.lang.String uri)
Creates a new element with the supplied (local) name and a namespace given by a URI. |
|
Element(java.lang.String name,
java.lang.String prefix,
java.lang.String uri)
Creates a new element with the supplied (local) name and a namespace given by the supplied prefix and URI combination. |
| Method Summary | |
Element |
addContent(java.util.Collection collection)
Appends all children in the given collection to the end of the content list. |
Element |
addContent(Content child)
Appends the child to the end of the element's content list. |
Element |
addContent(int index,
java.util.Collection c)
Inserts the content in a collection into the content list at the given index. |
Element |
addContent(int index,
Content child)
Inserts the child into the content list at the given index. |
Element |
addContent(java.lang.String str)
This adds text content to this element. |
void |
addNamespaceDeclaration(Namespace additional)
Adds a namespace declarations to this element. |
java.lang.Object |
clone()
This returns a deep clone of this element. |
java.util.List |
cloneContent()
Returns a list containing detached clones of this parent's content list. |
java.util.List |
getAdditionalNamespaces()
Returns a list of the additional namespace declarations on this element. |
Attribute |
getAttribute(java.lang.String name)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists. |
Attribute |
getAttribute(java.lang.String name,
Namespace ns)
This returns the attribute for this element with the given name and within the given Namespace, or null if no such attribute exists. |
java.util.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. |
java.lang.String |
getAttributeValue(java.lang.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. |
java.lang.String |
getAttributeValue(java.lang.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. |
java.lang.String |
getAttributeValue(java.lang.String name,
Namespace ns,
java.lang.String 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. |
java.lang.String |
getAttributeValue(java.lang.String name,
java.lang.String 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. |
Element |
getChild(java.lang.String name)
This returns the first child element within this element with the given local name and belonging to no namespace. |
Element |
getChild(java.lang.String name,
Namespace ns)
This returns the first child element within this element with the given local name and belonging to the given namespace. |
java.util.List |
getChildren()
This returns a List of all the child elements
nested directly (one level deep) within this element, as
Element objects. |
java.util.List |
getChildren(java.lang.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. |
java.util.List |
getChildren(java.lang.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. |
java.lang.String |
getChildText(java.lang.String name)
Returns the textual content of the named child element, or null if there's no such child. |
java.lang.String |
getChildText(java.lang.String name,
Namespace ns)
Returns the textual content of the named child element, or null if there's no such child. |
java.lang.String |
getChildTextNormalize(java.lang.String name)
Returns the normalized textual content of the named child element, or null if there's no such child. |
java.lang.String |
getChildTextNormalize(java.lang.String name,
Namespace ns)
Returns the normalized textual content of the named child element, or null if there's no such child. |
java.lang.String |
getChildTextTrim(java.lang.String name)
Returns the trimmed textual content of the named child element, or null if there's no such child. |
java.lang.String |
getChildTextTrim(java.lang.String name,
Namespace ns)
Returns the trimmed textual content of the named child element, or null if there's no such child. |
java.util.List |
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. |
java.util.List |
getContent(org.jdom.filter.Filter filter)
Return a filter view of this Element's content. |
Content |
getContent(int index)
Returns the child at the given index. |
int |
getContentSize()
Returns the number of children in this parent's content list. |
java.util.Iterator |
getDescendants()
Returns an iterator that walks over all descendants in document order. |
java.util.Iterator |
getDescendants(org.jdom.filter.Filter filter)
Returns an iterator that walks over all descendants in document order applying the Filter to return only elements that match the filter rule. |
java.lang.String |
getName()
Returns the (local) name of the element (without any namespace prefix). |
Namespace |
getNamespace()
Returns the element's Namespace. |
Namespace |
getNamespace(java.lang.String prefix)
Returns the Namespace corresponding to the given prefix in scope for this element. |
java.lang.String |
getNamespacePrefix()
Returns the namespace prefix of the element or an empty string if none exists. |
java.lang.String |
getNamespaceURI()
Returns the namespace URI mapped to this element's prefix (or the in-scope default namespace URI if no prefix). |
java.lang.String |
getQualifiedName()
Returns the full name of the element, in the form [namespacePrefix]:[localName]. |
java.lang.String |
getText()
Returns the textual content directly held under this element as a string. |
java.lang.String |
getTextNormalize()
Returns the textual content of this element with all surrounding whitespace removed and internal whitespace normalized to a single space. |
java.lang.String |
getTextTrim()
Returns the textual content of this element with all surrounding whitespace removed. |
java.lang.String |
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.) |
int |
indexOf(Content child)
Returns the index of the supplied child in the content list, or -1 if not a child of this parent. |
boolean |
isAncestor(Element element)
Determines if this element is the ancestor of another element. |
boolean |
isRootElement()
Returns whether this element is a root element. |
private void |
readObject(java.io.ObjectInputStream in)
|
boolean |
removeAttribute(Attribute attribute)
This removes the supplied Attribute should it exist. |
boolean |
removeAttribute(java.lang.String name)
This removes the attribute with the given name and within no namespace. |
boolean |
removeAttribute(java.lang.String name,
Namespace ns)
This removes the attribute with the given name and within the given Namespace. |
boolean |
removeChild(java.lang.String name)
This removes the first child element (one level deep) with the given local name and belonging to no namespace. |
boolean |
removeChild(java.lang.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(java.lang.String name)
This removes all child elements (one level deep) with the given local name and belonging to no namespace. |
boolean |
removeChildren(java.lang.String name,
Namespace ns)
This removes all child elements (one level deep) with the given local name and belonging to the given namespace. |
java.util.List |
removeContent()
Removes all child content from this parent. |
boolean |
removeContent(Content child)
Removes a single child node from the content list. |
java.util.List |
removeContent(org.jdom.filter.Filter filter)
Remove all child content from this parent matching the supplied filter. |
Content |
removeContent(int index)
Removes and returns the child at the given index, or returns null if there's no such child. |
void |
removeNamespaceDeclaration(Namespace additionalNamespace)
Removes an additional namespace declarations from this element. |
Element |
setAttribute(Attribute attribute)
This sets an attribute value for this element. |
Element |
setAttribute(java.lang.String name,
java.lang.String value)
This sets an attribute value for this element. |
Element |
setAttribute(java.lang.String name,
java.lang.String value,
Namespace ns)
This sets an attribute value for this element. |
Element |
setAttributes(java.util.List newAttributes)
This sets the attributes of the element. |
Element |
setContent(java.util.Collection newContent)
This sets the content of the element. |
Element |
setContent(Content child)
Set this element's content to be the supplied child. |
Parent |
setContent(int index,
java.util.Collection collection)
Replace the child at the given index whith the supplied collection. |
Element |
setContent(int index,
Content child)
Replace the current child the given index with the supplied child. |
Element |
setName(java.lang.String name)
Sets the (local) name of the element. |
Element |
setNamespace(Namespace namespace)
Sets the element's Namespace. |
Element |
setText(java.lang.String text)
Sets the content of the element to be the text given. |
java.lang.String |
toString()
This returns a String representation of the
Element, suitable for debugging. |
private void |
writeObject(java.io.ObjectOutputStream out)
|
| Methods inherited from class org.jdom.Content |
detach, equals, getDocument, getParent, getParentElement, hashCode, setParent |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.jdom.Parent |
getDocument, getParent |
| Field Detail |
CVS_ID
private static final java.lang.String CVS_ID
- See Also:
- Constant Field Values
INITIAL_ARRAY_SIZE
private static final int INITIAL_ARRAY_SIZE
- See Also:
- Constant Field Values
name
protected java.lang.String name
- The local name of the element
namespace
protected transient Namespace namespace
- The namespace of the element
additionalNamespaces
protected transient java.util.List additionalNamespaces
- Additional namespace declarations to store on this element; useful
during output
attributes
AttributeList attributes
- The attributes of the element. Subclassers have to
track attributes using their own mechanism.
content
ContentList content
- The content of the element. Subclassers have to
track content using their own mechanism.
| 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(java.lang.String name, Namespace namespace)
- Creates a new element with the supplied (local) name and namespace. If
the provided namespace is null, the element will have no namespace.
Element
public Element(java.lang.String name)
- Create a new element with the supplied (local) name and no namespace.
Element
public Element(java.lang.String name, java.lang.String uri)
- Creates a new element with the supplied (local) name and a namespace
given by a URI. The element will be put into the unprefixed (default)
namespace.
Element
public Element(java.lang.String name, java.lang.String prefix, java.lang.String uri)
- Creates a new element with the supplied (local) name and a namespace
given by the supplied prefix and URI combination.
| Method Detail |
getName
public java.lang.String getName()
- Returns the (local) name of the element (without any namespace prefix).
setName
public Element setName(java.lang.String name)
- Sets the (local) name of the element.
getNamespace
public Namespace getNamespace()
- Returns the element's Namespace.
setNamespace
public Element setNamespace(Namespace namespace)
- Sets the element's Namespace. If the provided namespace is null,
the element will have no namespace.
getNamespacePrefix
public java.lang.String getNamespacePrefix()
- Returns the namespace prefix of the element or an empty string if none
exists.
getNamespaceURI
public java.lang.String getNamespaceURI()
- Returns the namespace URI mapped to this element's prefix (or the
in-scope default namespace URI if no prefix). If no mapping is found, an
empty string is returned.
getNamespace
public Namespace getNamespace(java.lang.String prefix)
- Returns the Namespace corresponding to the given prefix in scope
for this element. This involves searching up the tree, so the results
depend on the current location of the element. Returns null if there is
no namespace in scope with the given prefix at this point in the
document.
getQualifiedName
public java.lang.String getQualifiedName()
- Returns the full name of the element, in the form
[namespacePrefix]:[localName]. If the element does not have a namespace
prefix, then the local name is returned.
addNamespaceDeclaration
public void addNamespaceDeclaration(Namespace additional)
- Adds 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.
It's used during output to for stylistic reasons move namespace
declarations higher in the tree than they would have to be.
removeNamespaceDeclaration
public void removeNamespaceDeclaration(Namespace additionalNamespace)
- Removes an additional 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.
getAdditionalNamespaces
public java.util.List getAdditionalNamespaces()
- Returns a list of the additional namespace declarations on this element.
This includes only additional namespace, not the namespace of the element
itself, which can be obtained through
getNamespace()55 . If there are no additional declarations, this returns an empty list. Note, the returned list is unmodifiable.
getValue
public java.lang.String 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.)
isRootElement
public boolean isRootElement()
- Returns whether this element is a root element. This can be used in
tandem with
Content.getParent()55 to determine if an element has any "attachments" to a parent element or document.
getContentSize
public int getContentSize()
- Description copied from interface:
Parent - Returns the number of children in this parent's content list.
Children may be any Content type.
- Specified by:
getContentSizein interfaceParent
indexOf
public int indexOf(Content child)
- Description copied from interface:
Parent - Returns the index of the supplied child in the content list,
or -1 if not a child of this parent.
getText
public java.lang.String getText()
- Returns the textual content directly held under this element as a string.
This includes all text within this single element, including whitespace
and CDATA sections if they exist. It's essentially the concatenation of
all Text and CDATA nodes returned by
getContent()55 . The call does not recurse into child elements. If no textual value exists for the element, an empty string is returned.
getTextTrim
public java.lang.String getTextTrim()
- 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.
getTextNormalize
public java.lang.String getTextNormalize()
- 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.
getChildText
public java.lang.String getChildText(java.lang.String name)
- Returns the textual content of the named child element, or null if
there's no such child. This method is a convenience because calling
getChild().getText()can throw a NullPointerException.
getChildTextTrim
public java.lang.String getChildTextTrim(java.lang.String name)
- Returns the trimmed textual content of the named child element, or null
if there's no such child. See
for details of text trimming.getTextTrim()55
getChildTextNormalize
public java.lang.String getChildTextNormalize(java.lang.String name)
- Returns the normalized textual content of the named child element, or
null if there's no such child. See
for details of text normalizing.getTextNormalize()55
getChildText
public java.lang.String getChildText(java.lang.String name, Namespace ns)
- Returns the textual content of the named child element, or null if
there's no such child.
getChildTextTrim
public java.lang.String getChildTextTrim(java.lang.String name, Namespace ns)
- Returns the trimmed textual content of the named child element, or null
if there's no such child.
getChildTextNormalize
public java.lang.String getChildTextNormalize(java.lang.String name, Namespace ns)
- Returns the normalized textual content of the named child element, or
null if there's no such child.
setText
public Element setText(java.lang.String text)
- 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
instead. Setting a null text value is equivalent to setting an empty string value.setContent(java.util.Collection)55
getContent
public java.util.List getContent()
- This returns the full content of the element as a List which
may contain objects of type
Text,Element,Comment,ProcessingInstruction,CDATA, andEntityRef. 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.Sequential traversal through the List is best done with an Iterator since the underlying implement of List.size() may require walking the entire list.
- Specified by:
getContentin interfaceParent
getContent
public java.util.List getContent(org.jdom.filter.Filter filter)
- Return a filter view of this
Element's content.Sequential traversal through the List is best done with a Iterator since the underlying implement of List.size() may require walking the entire list.
- Specified by:
getContentin interfaceParent
removeContent
public java.util.List removeContent()
- Removes all child content from this parent.
- Specified by:
removeContentin interfaceParent
removeContent
public java.util.List removeContent(org.jdom.filter.Filter filter)
- Remove all child content from this parent matching the supplied filter.
- Specified by:
removeContentin interfaceParent
setContent
public Element setContent(java.util.Collection newContent)
- This sets the content of the element. The supplied List should
contain only objects of type
Element,Text,CDATA,Comment,ProcessingInstruction, andEntityRef.When all objects in the supplied List are legal and before the new content is added, all objects in the old content will have their parentage set to null (no parent) and the old content list will be cleared. This has the effect that any active list (previously obtained with a call to
getContent()55 orgetChildren()55 ) will also change to reflect the new content. In addition, all objects in the supplied List will have their parentage set to this element, but the List itself will not be "live" and further removals and additions will have no effect on this elements content. If the user wants to continue working with a "live" list, then a call to setContent should be followed by a call togetContent()55 orgetChildren()55 to obtain a "live" version of the content.Passing a null or empty List clears the existing content.
In event of an exception the original content will be unchanged and the objects in the supplied content will be unaltered.
setContent
public Element setContent(int index, Content child)
- Replace the current child the given index with the supplied child.
In event of an exception the original content will be unchanged and the supplied child will be unaltered.
setContent
public Parent setContent(int index, java.util.Collection collection)
- Replace the child at the given index whith the supplied
collection.
In event of an exception the original content will be unchanged and the content in the supplied collection will be unaltered.
addContent
public Element addContent(java.lang.String str)
- This adds text content to this element. It does not replace the
existing content as does
setText().
addContent
public Element addContent(Content child)
- Appends the child to the end of the element's content list.
addContent
public Element addContent(java.util.Collection collection)
- Appends all children in the given collection to the end of
the content list. In event of an exception during add the
original content will be unchanged and the objects in the supplied
collection will be unaltered.
addContent
public Element addContent(int index, Content child)
- Inserts the child into the content list at the given index.
addContent
public Element addContent(int index, java.util.Collection c)
- Inserts the content in a collection into the content list
at the given index. In event of an exception the original content
will be unchanged and the objects in the supplied collection will be
unaltered.
cloneContent
public java.util.List cloneContent()
- Description copied from interface:
Parent - Returns a list containing detached clones of this parent's content list.
- Specified by:
cloneContentin interfaceParent
getContent
public Content getContent(int index)
- Description copied from interface:
Parent - Returns the child at the given index.
- Specified by:
getContentin interfaceParent
removeContent
public boolean removeContent(Content child)
- Description copied from interface:
Parent - Removes a single child node from the content list.
- Specified by:
removeContentin interfaceParent
removeContent
public Content removeContent(int index)
- Description copied from interface:
Parent - Removes and returns the child at the given
index, or returns null if there's no such child.
- Specified by:
removeContentin interfaceParent
setContent
public Element setContent(Content child)
- Set this element's content to be the supplied child.
If the supplied child is legal content for this parent and before it is added, all content in the current content list will be cleared and all current children will have their parentage set to null.
This has the effect that any active list (previously obtained with a call to one of the
getContent()55 methods will also change to reflect the new content. In addition, all content in the supplied collection will have their parentage set to this parent. If the user wants to continue working with a "live" list of this parent's child, then a call to setContent should be followed by a call to one of thegetContent()55 methods to obtain a "live" version of the children.Passing a null child clears the existing content.
In event of an exception the original content will be unchanged and the supplied child will be unaltered.
isAncestor
public boolean isAncestor(Element element)
- Determines if this element is the ancestor of another element.
getAttributes
public java.util.List getAttributes()
This returns the complete set of attributes for this element, as a
ListofAttributeobjects 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.
getAttribute
public Attribute getAttribute(java.lang.String name)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
getAttribute
public Attribute getAttribute(java.lang.String name, Namespace ns)
This returns the attribute for this element with the given name and within the given Namespace, or null if no such attribute exists.
getAttributeValue
public java.lang.String getAttributeValue(java.lang.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.
getAttributeValue
public java.lang.String getAttributeValue(java.lang.String name, java.lang.String 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.
getAttributeValue
public java.lang.String getAttributeValue(java.lang.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.
getAttributeValue
public java.lang.String getAttributeValue(java.lang.String name, Namespace ns, java.lang.String 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.
setAttributes
public Element setAttributes(java.util.List newAttributes)
This sets the attributes of the element. The supplied List should contain only objects of type
Attribute.When all objects in the supplied List are legal and before the new attributes are added, all old attributes will have their parentage set to null (no parent) and the old attribute list will be cleared. This has the effect that any active attribute list (previously obtained with a call to
getAttributes()55 ) will also change to reflect the new attributes. In addition, all attributes in the supplied List will have their parentage set to this element, but the List itself will not be "live" and further removals and additions will have no effect on this elements attributes. If the user wants to continue working with a "live" attribute list, then a call to setAttributes should be followed by a call togetAttributes()55 to obtain a "live" version of the attributes.Passing a null or empty List clears the existing attributes.
In cases where the List contains duplicate attributes, only the last one will be retained. This has the same effect as calling
setAttribute(Attribute)55 sequentially.In event of an exception the original attributes will be unchanged and the attributes in the supplied attributes will be unaltered.
setAttribute
public Element setAttribute(java.lang.String name, java.lang.String value)
This sets an attribute value for this element. Any existing attribute with the same name and namespace URI is removed.
setAttribute
public Element setAttribute(java.lang.String name, java.lang.String value, Namespace ns)
This sets an attribute value for this element. Any existing attribute with the same name and namespace URI is removed.
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.
removeAttribute
public boolean removeAttribute(java.lang.String name)
This removes the attribute with the given name and within no namespace. If no such attribute exists, this method does nothing.
removeAttribute
public boolean removeAttribute(java.lang.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.
removeAttribute
public boolean removeAttribute(Attribute attribute)
This removes the supplied Attribute should it exist.
toString
public java.lang.String toString()
This returns a
Stringrepresentation of theElement, suitable for debugging. If the XML representation of theElementis desired,org.jdom.output.XMLOutputter#outputString(Element)should be used.
clone
public java.lang.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.
writeObject
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
getDescendants
public java.util.Iterator getDescendants()
- Returns an iterator that walks over all descendants in document order.
- Specified by:
getDescendantsin interfaceParent
getDescendants
public java.util.Iterator getDescendants(org.jdom.filter.Filter filter)
- Returns an iterator that walks over all descendants in document order
applying the Filter to return only elements that match the filter rule.
With filters you can match only Elements, only Comments, Elements or
Comments, only Elements with a given name and/or prefix, and so on.
- Specified by:
getDescendantsin interfaceParent
getChildren
public java.util.List getChildren()
- This returns a
Listof all the child elements nested directly (one level deep) within this element, asElementobjects. 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.Sequential traversal through the List is best done with a Iterator since the underlying implement of List.size() may not be the most efficient.
No recursion is performed, so elements nested two levels deep would have to be obtained with:
Iterator itr = (currentElement.getChildren()).iterator(); while(itr.hasNext()) { Element oneLevelDeep = (Element)itr.next(); List twoLevelsDeep = oneLevelDeep.getChildren(); // Do something with these children }
getChildren
public java.util.List getChildren(java.lang.String name)
- This returns a
Listof all the child elements nested directly (one level deep) within this element with the given local name and belonging to no namespace, returned asElementobjects. 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
for a code example.getChildren()55
getChildren
public java.util.List getChildren(java.lang.String name, Namespace ns)
- This returns a
Listof all the child elements nested directly (one level deep) within this element with the given local name and belonging to the given Namespace, returned asElementobjects. 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
for a code example.getChildren()55
getChild
public Element getChild(java.lang.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.
getChild
public Element getChild(java.lang.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.
removeChild
public boolean removeChild(java.lang.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.
removeChild
public boolean removeChild(java.lang.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.
removeChildren
public boolean removeChildren(java.lang.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.
removeChildren
public boolean removeChildren(java.lang.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.
|
|||||||||
| Home >> All >> org >> [ jdom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC