public class XElement extends XContainer implements java.lang.Iterable<XElement>
XElement
is an entry in a xml-file. It has a name, can have children
and attributes, and might have a value.Constructor and Description |
---|
XElement(java.lang.String name)
Creates a new entry with given name.
|
Modifier and Type | Method and Description |
---|---|
XElement |
addAttribute(XAttribute attribute)
Adds a new attribute to this entry.
|
XElement |
addBoolean(java.lang.String name,
boolean value)
Adds a new attribute to this entry.
|
XElement |
addByte(java.lang.String name,
byte value)
Adds a new attribute to this entry.
|
XElement |
addByteArray(java.lang.String name,
byte[] value)
Adds a new attribute to this entry.
|
XElement |
addChar(java.lang.String name,
char value)
Adds a new attribute to this entry.
|
XElement |
addDouble(java.lang.String name,
double value)
Adds a new attribute to this entry.
|
XElement |
addElement(java.lang.String name)
Creates and adds a new element.
|
void |
addElement(XElement element)
Adds a new element to this element.
|
XElement |
addFloat(java.lang.String name,
float value)
Adds a new attribute to this entry.
|
XElement |
addInt(java.lang.String name,
int value)
Adds a new attribute to this entry.
|
XElement |
addLong(java.lang.String name,
long value)
Adds a new attribute to this entry.
|
XElement |
addShort(java.lang.String name,
short value)
Adds a new attribute to this entry.
|
XElement |
addString(java.lang.String name,
java.lang.String value)
Adds a new attribute to this entry.
|
boolean |
attributeExists(java.lang.String name)
Tells whether the attribute
name exists. |
XAttribute[] |
attributes()
Gets all attributes of this entry.
|
XElement[] |
children()
Gets all children of this entry.
|
XElement |
copy()
Creates an independent copy of this container.
|
void |
copy(XElement original)
Makes a copy of all the elements of
original
and stores them in this container. |
XAttribute |
getAttribute(java.lang.String name)
Searches an attribute with the given name.
|
boolean |
getBoolean(java.lang.String name)
Gets the value of an attribute.
|
byte |
getByte(java.lang.String name)
Gets the value of an attribute.
|
byte[] |
getByteArray(java.lang.String name)
Gets the value of an attribute.
|
char |
getChar(java.lang.String name)
Gets the value of an attribute.
|
double |
getDouble(java.lang.String name)
Gets the value of an attribute.
|
XElement |
getElement(int index)
Gets the index'th child of this element.
|
XElement |
getElement(java.lang.String name)
Gets the first element with the given name.
|
int |
getElementCount()
Gets the number of children this element has.
|
XElement[] |
getElements(java.lang.String... names)
Searches all children which have one of the name
names . |
XElement[] |
getElements(java.lang.String name)
Gets all children with a given name.
|
float |
getFloat(java.lang.String name)
Gets the value of an attribute.
|
int |
getInt(java.lang.String name)
Gets the value of an attribute.
|
long |
getLong(java.lang.String name)
Gets the value of an attribute.
|
java.lang.String |
getName()
Gets the name of this attribute.
|
short |
getShort(java.lang.String name)
Gets the value of an attribute.
|
java.lang.String |
getString()
Gets the value of this container as string.
|
java.lang.String |
getString(java.lang.String name)
Gets the value of an attribute.
|
java.util.Iterator<XElement> |
iterator() |
XAttribute |
removeAttribute(java.lang.String name)
Removes the attribute with name
name from this XElement . |
boolean |
removeAttribute(XAttribute attribute)
Removes the attribute
attribute from this XElement . |
boolean |
removeElement(XElement element)
Removes the child
element from this XElement . |
void |
setName(java.lang.String name)
Sets the name of this attribute.
|
void |
setString(java.lang.String s)
Sets the value of this container.
|
java.lang.String |
toString() |
copy, getBoolean, getByte, getByteArray, getChar, getDouble, getFloat, getInt, getLong, getShort, getValue, setBoolean, setByte, setByteArray, setChar, setDouble, setFloat, setInt, setLong, setShort, setValue
public XElement(java.lang.String name)
name
- the name of this entrypublic XElement copy()
XContainer
copy
in class XContainer
public void copy(XElement original)
original
and stores them in this container.original
- the element to copypublic void setName(java.lang.String name)
name
- the new namepublic java.lang.String getName()
public java.util.Iterator<XElement> iterator()
iterator
in interface java.lang.Iterable<XElement>
public XAttribute[] attributes()
public XElement[] children()
public XElement addAttribute(XAttribute attribute)
attribute
- the new attributethis
public XAttribute removeAttribute(java.lang.String name)
name
from this XElement
.name
- the name of the attribute to removenull
if not foundpublic boolean removeAttribute(XAttribute attribute)
attribute
from this XElement
.attribute
- the attribute to removetrue
if attribute
was removedpublic XElement addByte(java.lang.String name, byte value)
name
- the name of the attributevalue
- the value of the attributethis
public XElement addShort(java.lang.String name, short value)
name
- the name of the attributevalue
- the value of the attributethis
public XElement addInt(java.lang.String name, int value)
name
- the name of the attributevalue
- the value of the attributethis
public XElement addLong(java.lang.String name, long value)
name
- the name of the attributevalue
- the value of the attributethis
public XElement addFloat(java.lang.String name, float value)
name
- the name of the attributevalue
- the value of the attributethis
public XElement addDouble(java.lang.String name, double value)
name
- the name of the attributevalue
- the value of the attributethis
public XElement addChar(java.lang.String name, char value)
name
- the name of the attributevalue
- the value of the attributethis
public XElement addString(java.lang.String name, java.lang.String value)
name
- the name of the attributevalue
- the value of the attributethis
public XElement addBoolean(java.lang.String name, boolean value)
name
- the name of the attributevalue
- the value of the attributethis
public XElement addByteArray(java.lang.String name, byte[] value)
name
- the name of the attributevalue
- the value of the attributethis
public boolean attributeExists(java.lang.String name)
name
exists.name
- the name to searchtrue
if such an attribute existspublic XAttribute getAttribute(java.lang.String name)
name
- the name of the attributepublic byte getByte(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public short getShort(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public int getInt(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public long getLong(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public float getFloat(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public double getDouble(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public char getChar(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public java.lang.String getString(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public boolean getBoolean(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public byte[] getByteArray(java.lang.String name)
name
- the name of the attributeXException
- if the attribute does not exist or if the value
is in the wrong formatgetAttribute(String)
public boolean removeElement(XElement element)
element
from this XElement
.element
- the element to removetrue
if element
was removed, false
otherwisepublic void addElement(XElement element)
element
- the new childpublic XElement addElement(java.lang.String name)
name
- the name of the new elementpublic XElement getElement(java.lang.String name)
name
- the name of the elementnull
public int getElementCount()
public XElement getElement(int index)
index
- the index of the childpublic XElement[] getElements(java.lang.String name)
name
- the name each child must havepublic XElement[] getElements(java.lang.String... names)
names
.names
- the names to searchpublic void setString(java.lang.String s)
XContainer
setString
in class XContainer
s
- the valuepublic java.lang.String getString()
XContainer
getString
in class XContainer
public java.lang.String toString()
toString
in class java.lang.Object