Loop through XML data efficiently
in
Programming Questions
•
2 years ago
I'm trying to load data from an XML file once and then again after changing the child to create a heat map. Is there a way to do this without having to create a loop for each for new child? In this case I want a row for each month of unemployment data for every state. Thanks.
- void setup() {
- size(600, 600, P3D);
- background(255);
- smooth();
- loadMonth();
- loadMonth2();
- }
- void draw() {
- }
- void loadMonth() {
- pushMatrix();
- for (int i = 0; i < 50; i++) {
- XMLElement xml = new XMLElement(this, "unemployment.xml");
- XMLElement stateData = xml.getChild(i);
- XMLElement monthlyData = stateData.getChild(1);
- String monthlyNumber = monthlyData.getContent();
- float monthlyFloat = float(monthlyNumber);
- float colorMap = map(monthlyFloat, 0, 15, 255, 0);
- fill(colorMap);
- noStroke();
- translate(10, 0, 0);
- rect(0, 0, 10, 10);
- }
- popMatrix();
- }
- void loadMonth2() {
- pushMatrix();
- for (int i = 0; i < 50; i++) {
- XMLElement xml = new XMLElement(this, "unemployment.xml");
- XMLElement stateData = xml.getChild(i);
- XMLElement monthlyData = stateData.getChild(2);
- String monthlyNumber = monthlyData.getContent();
- float monthlyFloat = float(monthlyNumber);
- float colorMap = map(monthlyFloat, 0, 15, 255, 0);
- fill(colorMap);
- noStroke();
- translate(10, 0, 0);
- rect(0, 10, 10, 10);
- }
- popMatrix();
- }
1