Element
@Deprecated public class Element extends Object implements Cloneable
Note that this class is not thread-safe. It should not be used from different threads at the same time. This applies even to read operations.
Note that the namespace URIs and local names are not checked for validity in this class.
Instances of this class cannot be created directly, using a constructor.
Instead, use ElementBuilder
to build an XML element, or
ElementParser
to parse an XML string.
Element
Modifier and Type | Class and Description |
---|---|
static class |
Element.QualifiedName
Deprecated.
Qualified name for an element or attribute.
|
Constructor and Description |
---|
Element(String localName)
Deprecated.
Creates a new
Element with no namespace. |
Element(String namespaceURI,
String localName)
Deprecated.
Creates a new
Element . |
Element(String namespacePrefix,
String namespaceURI,
String localName)
Deprecated.
Creates a new
Element . |
Modifier and Type | Method and Description |
---|---|
void |
addChild(Element child)
Deprecated.
Adds a new child element.
|
Object |
clone()
Deprecated.
Clones this object.
|
boolean |
equals(Object obj)
Deprecated.
|
String |
getAttribute(Element.QualifiedName qn)
Deprecated.
Gets the value of the attribute with the qualified name.
|
String |
getAttribute(String localName)
Deprecated.
Gets the value of an attribute that has no namespace.
|
String |
getAttribute(String namespaceURI,
String localName)
Deprecated.
Gets the value of the attribute with the specified namespace and local
name.
|
Map |
getAttributeMap()
Deprecated.
Gets the attributes of this element.
|
List |
getChildElements()
Deprecated.
Gets the list of all child elements.
|
List |
getChildElements(String name)
Deprecated.
Gets the list of child elements that match the specified name.
|
String |
getLocalName()
Deprecated.
Gets the local name.
|
String |
getNamespacePrefix()
Deprecated.
Gets the namespace prefix.
|
String |
getNamespaceURI()
Deprecated.
Gets the namespace URI.
|
String |
getText()
Deprecated.
Gets the character content, if any.
|
Element |
getUniqueChildElement()
Deprecated.
Gets the unique child of this element.
|
Element |
getUniqueChildElement(String elementName)
Deprecated.
Gets the unique child of this element with the specified name.
|
int |
hashCode()
Deprecated.
|
void |
removeAttribute(String localName)
Deprecated.
Removes the specified attribute.
|
void |
removeAttribute(String namespaceURI,
String localName)
Deprecated.
Removes the specified attribute.
|
void |
removeChild(Element child)
Deprecated.
Removes a child element.
|
void |
setAttribute(String localName,
String value)
Deprecated.
Sets the specified attribute.
|
void |
setAttribute(String namespaceURI,
String localName,
String value)
Deprecated.
Sets the specified attribute.
|
void |
setAttribute(String namespacePrefix,
String namespaceURI,
String localName,
String value)
Deprecated.
Sets the specified attribute.
|
void |
setLocalName(String localName)
Deprecated.
Sets the local name.
|
void |
setNamespacePrefix(String namespacePrefix)
Deprecated.
Sets the namespace prefix.
|
void |
setNamespaceURI(String namespaceURI)
Deprecated.
Sets the namespace URI.
|
void |
setText(String text)
Deprecated.
Sets the character content.
|
String |
toString()
Deprecated.
Overrides the
Object.toString() method to return
the element as its XML representation. |
public Element(String localName) throws IllegalArgumentException
Element
with no namespace.localName
- the local name of the element, cannot be null
.IllegalArgumentException
- if localName == null
.public Element(String namespaceURI, String localName) throws IllegalArgumentException
Element
.namespaceURI
- the namespace URI for the element, can be null
; an empty
string is equivalent to null
.localName
- the local name of the element, cannot be null
.IllegalArgumentException
- if localName == null
.public Element(String namespacePrefix, String namespaceURI, String localName) throws IllegalArgumentException
Element
.namespacePrefix
- the namespace prefix for the element, can be null
; an empty
string is equivalent to null
.namespaceURI
- the namespace URI for the element, can be null
; an empty
string is equivalent to null
.localName
- the local name of the element, cannot be null
.IllegalArgumentException
- if localName == null
.public void setNamespacePrefix(String namespacePrefix)
namespacePrefix
- the namespace prefix of this element, can be null
.
If the value if null
or an empty string, the element is
consider to have no namespace prefix.public String getNamespacePrefix()
null
if there is
none, but never an empty string.public void setNamespaceURI(String namespaceURI)
namespaceURI
- the namespace URI of this element, can be null
.
If the value if null
or an empty string, the element is
consider to have no namespace URI.public String getNamespaceURI()
null
if there is
none, but never an empty string.public String getLocalName()
null
.public void setLocalName(String localName) throws IllegalArgumentException
localName
- the local name of this element, cannot be null
.IllegalArgumentException
- if localName == null
.public void setAttribute(String localName, String value) throws IllegalArgumentException
localName
- the local name for the attribute, cannot be null
.value
- the value for the attribute, can be null
.IllegalArgumentException
- if localName == null
.public void setAttribute(String namespaceURI, String localName, String value) throws IllegalArgumentException
namespaceURI
- the namespace URI for the attribute, can be null
; an
empty string is equivalent to null
.localName
- the local name for the attribute, cannot be null
.value
- the value for the attribute, can be null
.IllegalArgumentException
- if localName == null
.public void setAttribute(String namespacePrefix, String namespaceURI, String localName, String value) throws IllegalArgumentException
namespacePrefix
- the namespace prefix for the attribute, can be null
; an
empty string is equivalent to null
.namespaceURI
- the namespace URI for the attribute, can be null
; an
empty string is equivalent to null
.localName
- the local name for the attribute, cannot be null
.value
- the value for the attribute, can be null
.IllegalArgumentException
- if localName == null
.public void removeAttribute(String localName) throws IllegalArgumentException
localName
- the local name for the attribute, cannot be null
.IllegalArgumentException
- if localName == null
.public void removeAttribute(String namespaceURI, String localName) throws IllegalArgumentException
namespaceURI
- the namespace URI for the attribute, can be null
; an
empty string is equivalent to null
.localName
- the local name for the attribute, cannot be null
.IllegalArgumentException
- if localName == null
.public Map getAttributeMap()
Map
(never null
) which contains the attributes;
each key in the Map
is a Element.QualifiedName
instance
(not null
) and each value in it is a String
instance (not null
).public String getAttribute(Element.QualifiedName qn) throws IllegalArgumentException
qn
- a combination of an optional namespace and a mandatory local name, or
null
.null
if such an attribute is either not
set or set to null
.IllegalArgumentException
- if qn == null
.public String getAttribute(String namespaceURI, String localName) throws IllegalArgumentException
namespaceURI
- the namespace URI for the attribute, can be null
; an
empty string is equivalent to null
; if specified this
string must be a valid namespace URI.localName
- the local name of the attribute, cannot be null
.null
if such an attribute is either not
set or set to null
.IllegalArgumentException
- if localName == null
.public String getAttribute(String localName) throws IllegalArgumentException
localName
- the local name of the attribute, cannot be null
.null
if the attribute is
either not set or set to null
.IllegalArgumentException
- if localName == null
.public void addChild(Element child) throws IllegalArgumentException
child
- the new child to add to this element, cannot be null
.IllegalArgumentException
- if child == null || child == this
.public void removeChild(Element child) throws IllegalArgumentException
child
- the child to be removed to this element, cannot be null
.IllegalArgumentException
- if child == null || child == this
.public List getChildElements()
List
containing all child elements; each
element in the list is another Element
instance;
never null
.public List getChildElements(String name) throws IllegalArgumentException
name
- the name for the child elements to match, cannot be
null
.List
containing each child element that matches the
specified name as another Element
instance;
never null
. The list cannot be modified.IllegalArgumentException
- if name == null
.public void setText(String text)
text
- the character content for this element, or null
.public String getText()
null
if no
text has been specified for this element.public Element getUniqueChildElement(String elementName) throws ParseException
elementName
- the name of the child element to get, or null
if the
element name is irrelevant.null
.ParseException
- if no child with the specified name was found,
or if more than one child with the specified name was found.public Element getUniqueChildElement() throws ParseException
null
.ParseException
- if no child was found or more than one child was found.public Object clone()
public String toString()
Object.toString()
method to return
the element as its XML representation.See http://www.xins.org/.