add get/setContent() for XML

This commit is contained in:
Ben Fry
2013-04-20 07:57:31 -04:00
parent 92c90b580c
commit fef259524c
4 changed files with 166 additions and 8 deletions

View File

@@ -765,6 +765,58 @@ public class XML implements Serializable {
}
public int getIntContent() {
return getIntContent(0);
}
public int getIntContent(int defaultValue) {
return PApplet.parseInt(node.getTextContent(), defaultValue);
}
public float getFloatContent() {
return getFloatContent(0);
}
public float getFloatContent(float defaultValue) {
return PApplet.parseFloat(node.getTextContent(), defaultValue);
}
public long getLongContent() {
return getLongContent(0);
}
public long getLongContent(long defaultValue) {
String c = node.getTextContent();
if (c != null) {
try {
return Long.parseLong(c);
} catch (NumberFormatException nfe) { }
}
return defaultValue;
}
public double getDoubleContent() {
return getDoubleContent(0);
}
public double getDoubleContent(double defaultValue) {
String c = node.getTextContent();
if (c != null) {
try {
return Double.parseDouble(c);
} catch (NumberFormatException nfe) { }
}
return defaultValue;
}
/**
* @webref xml:method
* @brief Sets the content of an element
@@ -774,6 +826,26 @@ public class XML implements Serializable {
}
public void setIntContent(int value) {
setContent(String.valueOf(value));
}
public void setFloatContent(float value) {
setContent(String.valueOf(value));
}
public void setLongContent(long value) {
setContent(String.valueOf(value));
}
public void setDoubleContent(double value) {
setContent(String.valueOf(value));
}
/**
* Format this XML data as a String.
*