Help with working with XMLElement in Processing, parsing data, storing values
in
Core Library Questions
•
1 year ago
Hi, I am working on a sketch that is pulling XML from a php page, parsing the xml content, and printing it once to the console. It seems to be working correctly so far, BUT
I need help with my next step, which is to continually store the content from the second-to-last xml Children, from the second to last xml child. If you run the following program, and look in the console, I am trying to store the second to last entry int, id int, steps float, lon float, and lat float, so that I can constantly compare the latest values with their previous ones. The sketch is below. I apologize if this isn't completely clear. Thanks in advance for any insights you can provide!
int lastId = -1;
boolean isFirstTime = true;
void setup() {
size(400, 400);
}
void draw() {
frameRate(1);
String url = "http://jonlinton.com/ipw/getsteps.php?id=" + lastId;
XMLElement xmlFeed = new XMLElement(this, url);
int numEntries = xmlFeed.getChildCount();
for (int i=0; i<numEntries; i++) {
XMLElement entry = xmlFeed.getChild(i);
XMLElement[] kids = entry.getChildren();
int id = int(kids[0].getContent());
lastId = max(id, lastId);
float steps = float(kids[1].getContent());
float lon = float(kids[2].getContent());
float lat = float(kids[3].getContent());
//if its the first time I checked for entries, don't print, if not, then go ahead
if (!isFirstTime) {
println("entry = " + i + " | id = " + id + " | steps = " + steps + " | lon = " + lon + " | lat = " + lat);
}
isFirstTime = false;
}
}
1