public class RXElement extends RXAttribute
RXElement
class represents an XML element and simply manages a list of XML elements
(recursively) and a list of attributes. It also inherrits from RXAttribute to get name and value.
For the sake of efficiency, when you need to iterate over a list of elements for a given name, you can do this:
for(int i=anElement.indexOf(elementName); i>=0; i=anElement.indexOf(elementName, i+1))
anElement.get(i).doThis();Constructor and Description |
---|
RXElement()
Creates a new element.
|
RXElement(java.lang.String aName)
Creates a new element with given name.
|
RXElement(java.lang.String aName,
java.lang.String aValue)
Creates a new element with given name and value.
|
Modifier and Type | Method and Description |
---|---|
RXElement |
add(RXAttribute anAttribute)
Adds the given attribute to this element's list of attributes.
|
RXElement |
add(java.lang.String aName,
boolean aValue)
Adds a new attribute with the given name and boolean value.
|
RXElement |
add(java.lang.String aName,
java.lang.Boolean aValue)
Adds a new attribute with the given name and Boolean value.
|
RXElement |
add(java.lang.String aName,
java.awt.Color color) |
RXElement |
add(java.lang.String aName,
double aValue)
Adds a new attribute with the given name and float value.
|
RXElement |
add(java.lang.String aName,
java.awt.Font aValue) |
RXElement |
add(java.lang.String aName,
int aValue)
Adds a new attribute with the given name and int value.
|
RXElement |
add(java.lang.String aName,
java.lang.Object aValue)
Adds a new attribute with the given name using the object's toString() method.
|
RXElement |
add(java.lang.String aName,
java.lang.String aValue)
Adds a new attribute with the given name and string value.
|
void |
addAll(RXElement anElement)
Adds all the given child elements and attributes of given element to this element.
|
void |
addAttribute(RXAttribute anAttribute)
Adds an attribute.
|
void |
addAttribute(RXAttribute anAttribute,
int anIndex)
Adds an attribute at given index.
|
void |
addElement(RXElement anElement)
Adds given element to elements list.
|
void |
addElement(RXElement anElement,
int anIndex)
Adds given element to elements list at given index.
|
RXElement |
get(int anIndex)
Returns the specific child element at the given index.
|
RXElement |
get(java.lang.String aName)
Returns the first child element with the given name.
|
RXAttribute |
getAttribute(int anIndex)
Returns the specific child attribute at the given index.
|
RXAttribute |
getAttribute(java.lang.String aName)
Returns the specific child attribute with the given name (or null if not found).
|
java.lang.Boolean |
getAttributeBooleanValue(java.lang.String aName)
Returns the Boolean value for the given attribute name.
|
java.lang.Boolean |
getAttributeBooleanValue(java.lang.String aName,
java.lang.Boolean defaultValue)
Returns the Boolean value for the given attribute name (or the given default value, if name not found).
|
boolean |
getAttributeBoolValue(java.lang.String aName)
Returns the boolean value for the given attribute name.
|
boolean |
getAttributeBoolValue(java.lang.String aName,
boolean defaultValue)
Returns the boolean value for the given attribute name (or the given default value, if name not found).
|
java.awt.Color |
getAttributeColorValue(java.lang.String aName,
java.awt.Color defaultValue) |
int |
getAttributeCount()
Returns the number of child attributes for this element.
|
java.lang.Enum |
getAttributeEnumValue(java.lang.String aName,
java.lang.Class enumClass,
java.lang.Enum defaultValue)
Returns the Enum of a specific type for the given attribute name (or the given default value, if name not found).
|
float |
getAttributeFloatValue(java.lang.String aName)
Returns the float value for the given attribute name.
|
float |
getAttributeFloatValue(java.lang.String aName,
float defaultValue)
Returns the float value for the given attribute name (or the given default value, if name not found).
|
java.awt.Font |
getAttributeFontValue(java.lang.String aName,
java.awt.Font defaultValue) |
int |
getAttributeIndex(RXAttribute anAttribute)
Returns this index of the given attribute.
|
int |
getAttributeIndex(java.lang.String aName)
Returns the index of the attribute with the given name (or -1 if not found).
|
int |
getAttributeIntValue(java.lang.String aName)
Returns the int value for the given attribute name.
|
int |
getAttributeIntValue(java.lang.String aName,
int defaultValue)
Returns the int value for the given attribute name (or the given default value, if name not found).
|
java.lang.Number |
getAttributeNumberValue(java.lang.String aName)
Returns the Number value for the given attribute name.
|
java.lang.Number |
getAttributeNumberValue(java.lang.String aName,
java.lang.Number defaultValue)
Returns the Number value for the given attribute name (or the given default value, if name not found).
|
java.util.List<RXAttribute> |
getAttributes()
Returns the list of child attributes for this element.
|
java.lang.String |
getAttributeValue(java.lang.String aName)
Returns the attribute string value for the given attribute name.
|
java.lang.String |
getAttributeValue(java.lang.String aName,
java.lang.String defaultValue)
Returns the string value for the given attribute name (or the given default value, if name not found).
|
byte[] |
getBytes()
Returns XML bytes for this element.
|
RXElement |
getElement(int anIndex)
Returns the individual element at given index.
|
static RXElement |
getElement(java.lang.Object aSource)
Returns a new element hierarchy loaded from aSource (File, String path, InputStream or whatever).
|
RXElement |
getElement(java.lang.String aName)
Returns the first element for a given name.
|
int |
getElementCount()
Returns the number of child elements.
|
int |
getElementCount(java.lang.String aName)
Returns the number of child elements with the given name.
|
int |
getElementIndex(RXElement anElement)
Returns the index of the given element.
|
int |
getElementIndex(java.lang.String aName,
int start)
Returns the index of element with given name.
|
java.util.List<RXElement> |
getElements()
Returns the list of elements.
|
java.util.List<RXElement> |
getElements(java.lang.String aName)
Returns the list of child elements with given name.
|
byte[] |
getValueBytes()
Returns the element value as bytes.
|
boolean |
hasAttribute(java.lang.String aName)
Checks for presence of an attribute.
|
int |
indexOf(java.lang.String aName)
Returns the index of the first child element with the given name.
|
int |
indexOf(java.lang.String aName,
int startIndex)
Returns the index of the first child element with the given name at or beyond the given index.
|
RXAttribute |
removeAttribute(int anIndex)
Removes the attribute at given index.
|
int |
removeAttribute(RXAttribute anAttribute)
Removes the given attribute.
|
RXAttribute |
removeAttribute(java.lang.String aName)
Removes the attribute with given name.
|
RXElement |
removeElement(int anIndex)
Removes element at given index.
|
int |
removeElement(RXElement anElement)
Removes given element.
|
RXElement |
removeElement(java.lang.String aName)
Removes the first element with given name and returns it.
|
java.util.List<RXElement> |
removeElements(java.lang.String aName)
Removes elements for given element name.
|
void |
setValueBytes(byte[] theBytes)
Sets the element value from bytes.
|
int |
size()
Returns child element list size.
|
java.lang.String |
toString()
Returns a string representation of this element (XML).
|
void |
write(java.lang.StringBuffer aSB,
int indent,
java.lang.String indentStr)
Writes the element to the given string buffer using the given indent level and indent string.
|
protected void |
writePreamble(java.lang.StringBuffer aSB,
int indent,
java.lang.String indentStr)
Writes the element to the given string buffer using the given indent level and indent string.
|
getFloatValue, getIntValue, getName, getNumberValue, getValue, setName, setValue
public RXElement()
public RXElement(java.lang.String aName)
public RXElement(java.lang.String aName, java.lang.String aValue)
public static RXElement getElement(java.lang.Object aSource)
public int getAttributeCount()
public RXAttribute getAttribute(int anIndex)
public java.util.List<RXAttribute> getAttributes()
public void addAttribute(RXAttribute anAttribute)
public void addAttribute(RXAttribute anAttribute, int anIndex)
public RXAttribute removeAttribute(int anIndex)
public int removeAttribute(RXAttribute anAttribute)
public RXAttribute removeAttribute(java.lang.String aName)
public int getAttributeIndex(RXAttribute anAttribute)
public RXAttribute getAttribute(java.lang.String aName)
public int getAttributeIndex(java.lang.String aName)
public int getElementCount()
public RXElement getElement(int anIndex)
public java.util.List<RXElement> getElements()
public void addElement(RXElement anElement)
public void addElement(RXElement anElement, int anIndex)
public RXElement removeElement(int anIndex)
public int removeElement(RXElement anElement)
public int getElementIndex(RXElement anElement)
public int getElementCount(java.lang.String aName)
public int getElementIndex(java.lang.String aName, int start)
public RXElement getElement(java.lang.String aName)
public RXElement removeElement(java.lang.String aName)
public java.util.List<RXElement> getElements(java.lang.String aName)
public java.util.List<RXElement> removeElements(java.lang.String aName)
public boolean hasAttribute(java.lang.String aName)
public java.lang.String getAttributeValue(java.lang.String aName)
public java.lang.String getAttributeValue(java.lang.String aName, java.lang.String defaultValue)
public boolean getAttributeBoolValue(java.lang.String aName)
public boolean getAttributeBoolValue(java.lang.String aName, boolean defaultValue)
public java.lang.Boolean getAttributeBooleanValue(java.lang.String aName)
public java.lang.Boolean getAttributeBooleanValue(java.lang.String aName, java.lang.Boolean defaultValue)
public int getAttributeIntValue(java.lang.String aName)
public int getAttributeIntValue(java.lang.String aName, int defaultValue)
public java.awt.Color getAttributeColorValue(java.lang.String aName, java.awt.Color defaultValue)
public float getAttributeFloatValue(java.lang.String aName)
public float getAttributeFloatValue(java.lang.String aName, float defaultValue)
public java.lang.Number getAttributeNumberValue(java.lang.String aName)
public java.lang.Number getAttributeNumberValue(java.lang.String aName, java.lang.Number defaultValue)
public java.lang.Enum getAttributeEnumValue(java.lang.String aName, java.lang.Class enumClass, java.lang.Enum defaultValue)
public java.awt.Font getAttributeFontValue(java.lang.String aName, java.awt.Font defaultValue)
public RXElement add(java.lang.String aName, java.lang.String aValue)
public RXElement add(java.lang.String aName, java.lang.Object aValue)
public RXElement add(java.lang.String aName, java.awt.Color color)
public RXElement add(java.lang.String aName, boolean aValue)
public RXElement add(java.lang.String aName, java.lang.Boolean aValue)
public RXElement add(java.lang.String aName, int aValue)
public RXElement add(java.lang.String aName, double aValue)
public RXElement add(java.lang.String aName, java.awt.Font aValue)
public int size()
public RXElement get(int anIndex)
public RXElement get(java.lang.String aName)
public int indexOf(java.lang.String aName)
public int indexOf(java.lang.String aName, int startIndex)
public RXElement add(RXAttribute anAttribute)
public void addAll(RXElement anElement)
public byte[] getValueBytes()
public void setValueBytes(byte[] theBytes)
public java.lang.String toString()
toString
in class RXAttribute
public byte[] getBytes()
public void write(java.lang.StringBuffer aSB, int indent, java.lang.String indentStr)
protected void writePreamble(java.lang.StringBuffer aSB, int indent, java.lang.String indentStr)