|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--org.koala.koalaxml.XML
koala XML class provides a simple way to handle and parse xml data. Its purpose
is to be used as a property or parameter/return type.
In this version support is included to handle attributes, nested tags, various types
of values (including dates).
Here is a brief example of how to parse and print a xml:
String text = "<xml><TagA att1 = 'hi att' att2='' att3='<%System.out.println(someThingToPrint);%>'>value of tagA</TagA>" +
"<TagB><TagC>value of tagC</TagC></TagB><TagD><%String coco=\"<Tag>I can put whatever i want in a scriptlet</Tag>\";%></TagD></xml>";
// to parse it and create an XML object out of the text
XML xml = new XML(text);
// now lets print the xml
System.out.println(xml.toString());
| Constructor Summary | |
XML()
Creates an empty XML object. |
|
XML(java.lang.String xml)
Creates a new XML object by parsing the given string, take note that this is a non-validating parser and it could parse invalid XML. |
|
| Method Summary | |
void |
addSibling(org.koala.koalaxml.XML sibling)
Adds a new tag as the last child of the root one. |
void |
deleteSibling()
Deletes the sibling at the current position |
void |
deleteSibling(java.lang.String name)
Deletes the first sibling from the current position that has the given name and positions on the next child. |
boolean |
equals(java.lang.Object xml)
Compares the XML object with another one |
boolean |
getAttributeBoolean(java.lang.String attributeName)
Returns the boolean value of the given attribute of the root tag. |
boolean |
getAttributeBoolean(java.lang.String attributeName,
boolean defaultValue)
|
double |
getAttributeDouble(java.lang.String attributeName)
Returns the double value of the given attribute of the root tag. |
double |
getAttributeDouble(java.lang.String attributeName,
double defaultValue)
|
java.util.GregorianCalendar |
getAttributeGregorianCalendar(java.lang.String attributeName)
Returns the GregorianCalendar (date) value of the given attribute of the root tag. |
java.util.GregorianCalendar |
getAttributeGregorianCalendar(java.lang.String attributeName,
java.util.GregorianCalendar defaultValue)
|
int |
getAttributeInt(java.lang.String attributeName)
Returns the integer value of the given attribute of the root tag. |
int |
getAttributeInt(java.lang.String attributeName,
int defaultValue)
|
long |
getAttributeLong(java.lang.String attributeName)
Returns the long value of the given attribute of the root tag. |
long |
getAttributeLong(java.lang.String attributeName,
long defaultValue)
|
java.lang.String |
getAttributeScriptlet(java.lang.String attributeName)
Returns the string value of the given attribute of the root tag, striping the sorrounding <% and %>. |
java.lang.String |
getAttributeScriptlet(java.lang.String attributeName,
java.lang.String defaultValue)
|
java.lang.String |
getAttributeString(java.lang.String attributeName)
Returns the string value of the given attribute of the root tag. |
java.lang.String |
getAttributeString(java.lang.String attributeName,
java.lang.String defaultValue)
|
java.lang.String |
getName()
Returns the name of the root tag |
boolean |
getValueBoolean()
Returns the boolean value of the root tag. |
double |
getValueDouble()
Returns the double value of the root tag |
java.util.GregorianCalendar |
getValueGregorianCalendar()
Returns the GregorianCalendar (date) value of the root tag. |
int |
getValueInt()
Returns the integer value of the root tag |
long |
getValueLong()
Returns the long value of the root tag |
java.lang.String |
getValueScriptlet()
Returns the value of the root element and strips the <% and %> that sorrounds scriptlets |
java.lang.String |
getValueString()
Returns the value of the root element |
boolean |
hasMoreSiblings()
Returns true if there is a sibling at the current position. |
java.util.Vector |
listAttributes()
Returns a vector containing the names of all the attributes of the root tag |
org.koala.koalaxml.XML |
nextSibling()
Returns the sibling at the current position |
org.koala.koalaxml.XML |
nextSibling(java.lang.String name)
Returns the first sibling that has the given name, searching from the current position in a circular way (restarting from the beginning if no one is found). |
void |
setAttributeBoolean(java.lang.String attributeName,
boolean value)
Changes or sets the value of a given attribute in the root tag. |
void |
setAttributeDouble(java.lang.String attributeName,
double value)
Changes or sets the value of a given attribute in the root tag. |
void |
setAttributeGregorianCalendar(java.lang.String attributeName,
java.util.GregorianCalendar value)
Changes or sets the value of a given attribute in the root tag. |
void |
setAttributeInt(java.lang.String attributeName,
int value)
Changes or sets the value of a given attribute in the root tag. |
void |
setAttributeLong(java.lang.String attributeName,
long value)
Changes or sets the value of a given attribute in the root tag. |
void |
setAttributeString(java.lang.String attributeName,
java.lang.String value)
Changes or sets the value of a given attribute in the root tag. |
void |
setName(java.lang.String name)
Changes or sets the name of the root element |
void |
setValueBoolean(boolean value)
Sets the value of the root tag to a given boolean. |
void |
setValueDouble(double value)
Sets the value of the root tag to a given double. |
void |
setValueGregorianCalendar(java.util.GregorianCalendar value)
Sets the value of the root tag to a given GregorianCalendar (date). |
void |
setValueInt(int value)
Sets the value of the root tag to a given integer. |
void |
setValueLong(long value)
Sets the value of the root tag to a given long. |
void |
setValueString(java.lang.String value)
Sets the value of the root tag to a given string. |
void |
top()
Moves the position to the first child of the root element |
java.lang.String |
toString()
Returns a string representation of the XML object, indented and with tag and attribute names in capital letters. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public XML()
public XML(java.lang.String xml)
throws XMLParseException
xml - The string containing the xml data
XMLParseException - If an error that prevents parsing is found| Method Detail |
public boolean hasMoreSiblings()
public org.koala.koalaxml.XML nextSibling()
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException - If there is no sibling at the current position (meaning its beyond the last one)
public void addSibling(org.koala.koalaxml.XML sibling)
throws XMLInvalidTagException,
java.lang.NullPointerException
sibling - The XML object that contains the info to be added
XMLInvalidTagException - If the root tag is a leaf and therefor cannot have children
java.lang.NullPointerException - If the sibling is null
public void deleteSibling()
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException - If there is no child at the current position (meaning the root element is a leaf or
you are beyond the last sibling)public void deleteSibling(java.lang.String name)
name - Name of the tag to be deleted
public org.koala.koalaxml.XML nextSibling(java.lang.String name)
throws java.lang.NullPointerException
name - Name to be found
java.lang.NullPointerException - If no name is given (either null or "")public void top()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Vector listAttributes()
public java.lang.String getName()
public void setName(java.lang.String name)
name - New namepublic java.lang.String getValueString()
public java.lang.String getValueScriptlet()
throws XMLInvalidTypeException
XMLInvalidTypeException - If the tag value is not a scriptlet code
public int getValueInt()
throws java.lang.NullPointerException,
XMLInvalidTypeException
java.lang.NullPointerException - If the tag is not a leaf and therefor dont have a value
XMLInvalidTypeException - If the value cannot be parsed to an int
public long getValueLong()
throws java.lang.NullPointerException,
XMLInvalidTypeException
java.lang.NullPointerException - If the tag is not a leaf and therefor dont have a value
XMLInvalidTypeException - If the value cannot be parsed to a long
public double getValueDouble()
throws java.lang.NullPointerException,
XMLInvalidTypeException
java.lang.NullPointerException - If the tag is not a leaf and therefor dont have a value
XMLInvalidTypeException - If the value cannot be parsed to a double
public java.util.GregorianCalendar getValueGregorianCalendar()
throws java.lang.NullPointerException,
XMLInvalidTypeException
java.lang.NullPointerException - If the tag is not a leaf and therefor dont have a value
XMLInvalidTypeException - If the value cannot be parsed to a GregorianCalendar
public boolean getValueBoolean()
throws java.lang.NullPointerException,
XMLInvalidTypeException
java.lang.NullPointerException - If the tag is not a leaf and therefor dont have a value
XMLInvalidTypeException - If the value cannot be parsed to a boolean
public void setValueString(java.lang.String value)
throws java.lang.NullPointerException
value - New value
java.lang.NullPointerException - If the value is nullpublic void setValueInt(int value)
value - New int valuepublic void setValueLong(long value)
value - New long valuepublic void setValueDouble(double value)
value - New double value
public void setValueGregorianCalendar(java.util.GregorianCalendar value)
throws java.lang.NullPointerException,
java.lang.Exception
value - New GregorianCalendar value
java.lang.NullPointerException - If the value is null
java.lang.Exception - Very rare, report if thrownpublic void setValueBoolean(boolean value)
value - New boolean value
public java.lang.String getAttributeString(java.lang.String attributeName,
java.lang.String defaultValue)
throws XMLInvalidTypeException,
java.lang.NullPointerException
XMLInvalidTypeException
java.lang.NullPointerException
public java.lang.String getAttributeString(java.lang.String attributeName)
throws java.lang.NullPointerException
attributeName - Name of the attribute
java.lang.NullPointerException - If no name is specified (either by providing null or "")
public java.lang.String getAttributeScriptlet(java.lang.String attributeName,
java.lang.String defaultValue)
throws XMLInvalidTypeException,
java.lang.NullPointerException
XMLInvalidTypeException
java.lang.NullPointerException
public java.lang.String getAttributeScriptlet(java.lang.String attributeName)
throws XMLInvalidTypeException,
java.lang.NullPointerException
attributeName - Attribute name
XMLInvalidTypeException - If attribute value is not a scriptlet
java.lang.NullPointerException - If attribute name is null or empty
public int getAttributeInt(java.lang.String attributeName,
int defaultValue)
throws XMLInvalidTypeException,
java.lang.NullPointerException
XMLInvalidTypeException
java.lang.NullPointerException
public int getAttributeInt(java.lang.String attributeName)
throws XMLInvalidTypeException,
java.lang.NullPointerException
attributeName - Name of the attribute
java.lang.NullPointerException - If no name is specified (either by providing null or "")
XMLInvalidTypeException - If the value cannot be parsed as an integer
public long getAttributeLong(java.lang.String attributeName,
long defaultValue)
throws XMLInvalidTypeException,
java.lang.NullPointerException
XMLInvalidTypeException
java.lang.NullPointerException
public long getAttributeLong(java.lang.String attributeName)
throws XMLInvalidTypeException,
java.lang.NullPointerException
attributeName - Name of the attribute
java.lang.NullPointerException - If no name is specified (either by providing null or "")
XMLInvalidTypeException - If the value cannot be parsed as a long
public double getAttributeDouble(java.lang.String attributeName,
double defaultValue)
throws XMLInvalidTypeException,
java.lang.NullPointerException
XMLInvalidTypeException
java.lang.NullPointerException
public double getAttributeDouble(java.lang.String attributeName)
throws XMLInvalidTypeException,
java.lang.NullPointerException
attributeName - Name of the attribute
java.lang.NullPointerException - If no name is specified (either by providing null or "")
XMLInvalidTypeException - If the value cannot be parsed as a double
public java.util.GregorianCalendar getAttributeGregorianCalendar(java.lang.String attributeName,
java.util.GregorianCalendar defaultValue)
throws XMLInvalidTypeException,
java.lang.NullPointerException
XMLInvalidTypeException
java.lang.NullPointerException
public java.util.GregorianCalendar getAttributeGregorianCalendar(java.lang.String attributeName)
throws XMLInvalidTypeException,
java.lang.NullPointerException
attributeName - Name of the attribute
java.lang.NullPointerException - If no name is specified (either by providing null or "")
XMLInvalidTypeException - If the value cannot be parsed as a GregorianCalendar
public boolean getAttributeBoolean(java.lang.String attributeName,
boolean defaultValue)
throws XMLInvalidTypeException,
java.lang.NullPointerException
XMLInvalidTypeException
java.lang.NullPointerException
public boolean getAttributeBoolean(java.lang.String attributeName)
throws XMLInvalidTypeException,
java.lang.NullPointerException
attributeName - Name of the attribute
java.lang.NullPointerException - If no name is specified (either by providing null or "")
XMLInvalidTypeException - If the value cannot be parsed as a boolean
public void setAttributeString(java.lang.String attributeName,
java.lang.String value)
throws java.lang.NullPointerException
attributeName - Attribute namevalue - New value
java.lang.NullPointerException - If the name is not specified (either by providing null or "") or if the value is null
public void setAttributeInt(java.lang.String attributeName,
int value)
throws java.lang.NullPointerException
attributeName - Attribute namevalue - New value
java.lang.NullPointerException - If the name is not specified (either by providing null or "")
public void setAttributeLong(java.lang.String attributeName,
long value)
throws java.lang.NullPointerException
attributeName - Attribute namevalue - New value
java.lang.NullPointerException - If the name is not specified (either by providing null or "")
public void setAttributeDouble(java.lang.String attributeName,
double value)
throws java.lang.NullPointerException
attributeName - Attribute namevalue - New value
java.lang.NullPointerException - If the name is not specified (either by providing null or "")
public void setAttributeGregorianCalendar(java.lang.String attributeName,
java.util.GregorianCalendar value)
throws java.lang.NullPointerException,
java.lang.Exception
attributeName - Attribute namevalue - New value
java.lang.NullPointerException - If the name is not specified (either by providing null or "") or if the value is null
java.lang.Exception - Very rare, report if thrown
public void setAttributeBoolean(java.lang.String attributeName,
boolean value)
throws java.lang.NullPointerException
attributeName - Attribute namevalue - New value
java.lang.NullPointerException - If the name is not specified (either by providing null or "")public boolean equals(java.lang.Object xml)
equals in class java.lang.Objectxml - Object to compare to
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||