|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jdom.Element
Attribute
defines behavior for an XML
attribute, modeled in Java. Methods allow the user
to obtain the value of the element's textual content,
obtain its attributes, and get its children.
Field Summary | |
protected java.util.List |
attributes
The attributes of the Element |
protected java.util.List |
content
The mixed content of the Element |
protected java.lang.String |
name
The local name of the Element |
protected java.lang.String |
prefix
The namespace prefix of the Element |
Constructor Summary | |
protected |
Element()
Default, no-args constructor for implementations to use if needed. |
|
Element(java.lang.String name)
This will create a new Element
with the supplied (local) name. |
|
Element(java.lang.String prefix,
java.lang.String name)
This will create a new Element
with the supplied namespace prefix and (local)
name. |
Method Summary | |
Element |
addAttribute(Attribute attribute)
This will add an to this
Element . |
Element |
addAttribute(java.lang.String name,
java.lang.String value)
This will add an to this
Element . |
Element |
addChild(Comment comment)
This will add a as a child of this
Element . |
Element |
addChild(Element element)
This will add an Element as a child of this
Element . |
Element |
addChild(Entity entity)
This will add an Entity as a child of this
Element . |
Element |
addChild(java.lang.String s)
This will add a String as a child of this
Element . |
Element |
addText(java.lang.String text)
This will add test to the content of this Element . |
Attribute |
getAttribute(java.lang.String name)
This will return the for the
specified attribute name on this Element . |
Attribute |
getAttribute(java.lang.String prefix,
java.lang.String name)
This will return the for the
specified attribute name on this Element . |
java.util.List |
getAttributes()
This returns the complete set of s for
this Element , in no
particular order. |
Element |
getChild(java.lang.String name)
This will return a List of all the XML
elements nested directly (one level deep) within
this Element whose names match the name
specified, each in Element
form. |
Element |
getChild(java.lang.String prefix,
java.lang.String name)
This will return the child s for the
specified element name on this Element . |
java.util.List |
getChildren()
This will return a List of all the XML
elements nested directly (one level deep) within
this Element , each in Element
form. |
java.util.List |
getChildren(java.lang.String name)
This will return a List of all the XML
elements nested directly (one level deep) within
this Element whose names match the name
specified, each in Element
form. |
java.util.List |
getChildren(java.lang.String prefix,
java.lang.String name)
This will return the children s for the
specified element name on this Element . |
java.lang.String |
getContent()
This will return the actual textual content of this Element . |
java.lang.String |
getFullName()
This returns the full name of the Element , in the form
[namespacePrefix]:[localName]. |
java.util.List |
getMixedContent()
This will return the content of the element. |
java.lang.String |
getName()
This returns the (local) name of the Element , without any
namespace prefix, if one exists. |
java.lang.String |
getNamespacePrefix()
This returns the namespace prefix of the Element , if
one exists. |
boolean |
hasMixedContent()
This will indicate whether the element has mixed content or not. |
void |
removeAttribute(java.lang.String name)
This will remove the Attribute with the given name. |
void |
removeAttribute(java.lang.String namespacePrefix,
java.lang.String localName)
This will remove the Attribute with the given name. |
boolean |
removeChild(Comment comment)
This will remove the specified Comment . |
boolean |
removeChild(Element element)
This will remove the specified Element . |
boolean |
removeChild(Entity entity)
This will remove the specified Entity . |
boolean |
removeChild(java.lang.String name)
This will remove the Element with the
specified name. |
boolean |
removeChild(java.lang.String prefix,
java.lang.String name)
This will remove the Element with the
specified name. |
boolean |
removeChildren()
This removes all children for this Element . |
boolean |
removeChildren(java.lang.String name)
This will remove the Element with the
specified name. |
boolean |
removeChildren(java.lang.String prefix,
java.lang.String name)
This will remove the Element with the
specified name. |
Element |
setAttributes(java.util.List attributes)
This will set all the attributes for this Element . |
Element |
setChildren(java.util.List children)
This will set the children of this Element to the
Element s within the supplied :ost . |
Element |
setContent(java.lang.String textContent)
This will set the textual content of the Element . |
Element |
setMixedContent(java.util.List mixedContent)
This will return the content of the element. |
Element |
setName(java.lang.String name)
This will set the name of the element. |
Element |
setName(java.lang.String prefix,
java.lang.String name)
This will set the name of the element. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected java.lang.String name
Element
protected java.lang.String prefix
Element
protected java.util.List attributes
Element
protected java.util.List content
Element
Constructor Detail |
protected Element()
Default, no-args constructor for implementations to use if needed.
public Element(java.lang.String prefix, java.lang.String name)
This will create a new Element
with the supplied namespace prefix and (local)
name.
prefix
- String
prefix for element.name
- String
name of element.public Element(java.lang.String name)
This will create a new Element
with the supplied (local) name. This assumes
that no prefix should be issued for the
Element
, and that it is in the
default namespace.
name
- String
name of element.Method Detail |
public java.lang.String getName()
This returns the (local) name of the
Element
, without any
namespace prefix, if one exists.
String
- element name.public java.lang.String getNamespacePrefix()
This returns the namespace prefix
of the Element
, if
one exists. Otherwise, an empty
String
is returned.
String
- namespace prefix.public java.lang.String getFullName()
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.
String
- full name of element.public Element setName(java.lang.String name)
This will set the name of the element. If the name specified has a namespace prefix (indicated by a colon), then the prefix is split from the element and handled. If no namespace prefix is supplied, the namespace prefix is empty.
name
- String
full name of element.Element
- this element modified.public Element setName(java.lang.String prefix, java.lang.String name)
This will set the name of the element. It allows a namespace prefix to be passed in as well as the local name of the element.
prefix
- String
prefix for name.name
- String
local name of element.Element
- this element modified.public java.lang.String getContent()
This will return the actual textual content of this
Element
. This will include all text within
this single element, including CDATA
sections
if they exist. If no textual value exists for the
Element
, an empty String
is returned.
String
- value for this element.public Element setContent(java.lang.String textContent)
This will set the textual content of the Element
.
If this Element
will have both textual content
and nexted elements,
should be used instead,
setMixedContent(java.util.List)
textContent
- String
content for Element
.Element
- this element modified.public boolean hasMixedContent()
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
,
should be used for getting
element data.
getMixedContent()
Note:I think there's a better way to do this, maybe store a member variable, but I'm too tired to really think of what it is... (brett).
boolean
- indicating whether there
is mixed content (both textual data and elements).public java.util.List getMixedContent()
This will return the content of the element. This should be
used when the
evaluates to hasMixedContent()
true
. When there is no mixed
content, it returns a List
with a single
String
(when only data is present) or a
List
with only elements (when only nested
elements are present).
List
- the mixed content of the
Element
: contains String
,
Element
, Comment
,
and Entity
objects.public Element setMixedContent(java.util.List mixedContent)
This will return the content of the element. This should be
used when the
evaluates to hasMixedContent()
true
. When there is no mixed
content, it returns a List
with a single
String
(when only data is present) or a
List
with only elements (when only nested
elements are present).
Element
- this element modified.public java.util.List getChildren()
This will return a List
of all the XML
elements nested directly (one level deep) within
this Element
, each in Element
form. If the Element
has no nested elements,
an empty list will be returned.
This performs no recursion, so an elements nested two levels deep would have to be obtained with:
List nestedElements = currentElement.getChildren();
for (int i=0; i<nestedElements.size(); i++) {
Element oneLevelDeep = (Element)nestedElements.get(i);
List twoLevelsDeep = oneLevelDeep.getChildren();
// Do something with these children
}
List
- list of nested
Element
instances for this element.public Element setChildren(java.util.List children)
This will set the children of this Element
to the
Element
s within the supplied :ost
.
All existing children of this Element
are replaced.
children
- List
of Element
s to add.Element
- this element modified.public java.util.List getChildren(java.lang.String name)
This will return a List
of all the XML
elements nested directly (one level deep) within
this Element
whose names match the name
specified, each in Element
form. If the Element
has no nested elements
that match the requested name, an empty list will be returned.
Either the raw name (XML 1.0: namespace prefix and local name) of the element can be provided (for example, JavaXML:Book), or simply the local name (XML Namespace aware: local name only) of the element (for example, Book), can be provided.
Please see the notes for
regarding how deep this search will go within element
nestings. Only elements directly nested within this getChildren()
Element
will be returned.
name
- String
name of attribute to return.List
- all matching child elements.public java.util.List getChildren(java.lang.String prefix, java.lang.String name)
This will return the children
s for the
specified element name on this Element
Element
. If
multiple elements exist for the specified name, all are
returned.
Please see the notes for
regarding how deep this search will go within element
nestings. Only elements directly nested within this getChildren()
Element
will be returned.
prefix
- String
prefix of elements to findname
- String
name of child elements to return.List
- the requested elements.public Element getChild(java.lang.String name) throws NoSuchElementException
This will return a List
of all the XML
elements nested directly (one level deep) within
this Element
whose names match the name
specified, each in Element
form. If the Element
has no nested elements
that match the requested name, an empty list will be returned.
Either the raw name (XML 1.0: namespace prefix and local name) of the element can be provided (for example, JavaXML:Book), or simply the local name (XML Namespace aware: local name only) of the element (for example, Book), can be provided.
Please see the notes for
regarding how deep this search will go within element
nestings. Only elements directly nested within this getChildren()
Element
will be returned.
name
- String
name of attribute to return.Element
- the first matching child element.NoSuchElementException
- - when the requested
XML element does not exist within this Element
.public Element getChild(java.lang.String prefix, java.lang.String name) throws NoSuchElementException
This will return the child
s for the
specified element name on this Element
Element
. If
multiple elements exist for the specified name, only the first is
returned.
Please see the notes for
regarding how deep this search will go within element
nestings. Only elements directly nested within this getChildren()
Element
will be returned.
prefix
- String
prefix of elements to findname
- String
name of child elements to return.Element
- the first matching child element.NoSuchElementException
- - when the requested
XML element does not exist within this Element
.public Element addText(java.lang.String text)
This will add test to the content of this
Element
.
text
- String
to add as content.Element
- this element modified.public Element addChild(Element element)
This will add an Element
as a child of this
Element
.
element
- Element
to add as a child.Element
- this element modified.public Element addChild(Entity entity)
This will add an Entity
as a child of this
Element
.
entity
- Entity
to add as a child.Element
- this element modified.public Element addChild(java.lang.String s)
This will add a String
as a child of this
Element
.
s
- String
to add as a child.Element
- this element modified.public boolean removeChild(Element element)
This will remove the specified Element
.
child
- Element
to delete.boolean
- whether deletion occurred.public boolean removeChild(Entity entity)
This will remove the specified Entity
.
child
- Entity
to delete.boolean
- whether deletion occurred.public boolean removeChild(java.lang.String name)
This will remove the Element
with the
specified name. If multiple Element
s
exist with that name, the first matching child is
removed.
Note:Currently, this does not assume that you want the
default namespace. I can perform
removeChild("foo:bar")
, and it does the right
thing. But if I have a document with elements
<foo:bar>
as well as <bar>
,
this currently removes the first of those when
removeChild("bar")
is invoked. Do we want to
explicitly enforce the default namespace (none) if no prefix
is given? (brett)
name
- String
name of child to delete.boolean
- whether deletion occurred.public boolean removeChild(java.lang.String prefix, java.lang.String name)
This will remove the Element
with the
specified name. If multiple Element
s
exist with that name, the first matching child is
removed.
prefix
- String
prefix of element to remove.name
- String
local name of child to delete.boolean
- whether deletion occurred.public boolean removeChildren(java.lang.String name)
This will remove the Element
with the
specified name. If multiple Element
s
exist with that name, all matching children are
removed.
Note:Currently, this does not assume that you want the
default namespace. I can perform
removeChild("foo:bar")
, and it does the right
thing. But if I have a document with elements
<foo:bar>
as well as <bar>
,
this currently removes the first of those when
removeChild("bar")
is invoked. Do we want to
explicitly enforce the default namespace (none) if no prefix
is given? (brett)
name
- String
name of child to delete.boolean
- whether deletion occurred.public boolean removeChildren(java.lang.String prefix, java.lang.String name)
This will remove the Element
with the
specified name. If multiple Element
s
exist with that name, the first matching child is
removed.
prefix
- String
prefix of element to remove.name
- String
local name of child to delete.boolean
- whether deletion occurred.public boolean removeChildren()
This removes all children for this Element
.
boolean
- whether deletion occurred.public Element addChild(Comment comment)
This will add a
as a child of this
Comment
Element
.
comment
- Comment
to add as a child.Element
- this element modified.public boolean removeChild(Comment comment)
This will remove the specified Comment
.
comment
- Comment
to delete.boolean
- whether deletion occurred.public java.util.List getAttributes()
This returns the complete set of
s for
this Attribute
Element
, in no
particular order.
List
- attributes for the element.public Attribute getAttribute(java.lang.String name) throws NoSuchAttributeException
This will return the
for the
specified attribute name on this Attribute
Element
.
Note:Currently, this does not assume that you want the
default namespace. I can perform
getAttribute("foo:bar")
, and it does the right
thing. But if I have a document with an element
with attributes foo:bar
as well as
bar
, this currently gets the
first of those when getAttribute("bar")
is invoked. Do we want to explicitly enforce the
default namespace (none) if no prefix is given? (brett)
name
- String
name of attribute to return.Attribute
- the requested attribute.NoSuchAttributeException
- - when the requested
XML attribute does not exist for this Element
.public Attribute getAttribute(java.lang.String prefix, java.lang.String name) throws NoSuchAttributeException
This will return the
for the
specified attribute name on this Attribute
Element
.
prefix
- String
prefix of attribute to returnname
- String
local name of attribute to return.Attribute
- the requested attribute.NoSuchAttributeException
- - when the requested
XML attribute does not exist for this Element
.public Element setAttributes(java.util.List attributes)
This will set all the attributes for this Element
.
attributes
- List
of attributes to add.Element
- this element modified.public Element addAttribute(Attribute attribute)
This will add an
to this
Attribute
Element
.
attribute
- Attribute
to add.Element
- this element modified.public Element addAttribute(java.lang.String name, java.lang.String value)
This will add an
to this
Attribute
Element
.
name
- name of the attribute to add.value
- value of the attribute to add.Element
- this element modified.public void removeAttribute(java.lang.String name)
This will remove the Attribute
with the given name.
Note:Currently, this does not assume that you want the
default namespace. I can perform
removeAttribute("foo:bar")
, and it does the right
thing. But if I have a document with an element
with attributes foo:bar
as well as
bar
, this currently removes the
first of those when removeAttribute("bar")
is invoked. Do we want to explicitly enforce the default
namespace (none) if no prefix is given? (brett)
fullName
- String
name of attribute to remove.public void removeAttribute(java.lang.String namespacePrefix, java.lang.String localName)
This will remove the Attribute
with the given name.
namespacePrefix
- String
prefix of
attribute to delete.localName
- String
name of attribute to remove.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |