mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 19:05:34 +01:00
add get/setContent() for XML
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user