Animation with XML Data
in
Contributed Library Questions
•
1 year ago
Hello,
I have a xml file containing some data and a processing sketch to read this data.
Want I want to do:
In my xml file I have several childs containing 4 attributes: Name, Surname, Age and City.
First I want to display the Name, 1 second later the surname, 1 second later the age and another second later the city. This animation has to work for the first three childs in my xml file at once. After about 6 seconds it has to display the 4th, 5th and 6th entry. And so on and so on. So no matter how many childs are in my xml file I only want to display three at one time.
Right now I am able to read through my whole xml file and get all of the children. But I only want the first three to appear with the animation of first showing the name, then the surname, age and the city.
Second Problem: As I want this as an animation I need to write my script into the draw(). Sadly the text becomes quite ugly as it overwrites the text every time it loops through draw.
Do have any suggestions how to figure this out? Do I need to use arrays or something to address the text outside the loop? I tried to work with pullMatrix () and pushMatrix() but this doesn't work.
So below you'll find my code so far and the content of my xml file. I'm glad for any help!!!!!
XML FILE
-
<?xml version="1.0" encoding="ISO-8859-1"?>
-
<pulses>
-
<Person>
-
<werte name="John" surname="Smith" age="39" city="London"/>
-
</Person>
-
<Person>
-
<werte name="Claire" surname="Walker" age="22" city="Paris"/>
-
</Person>
-
<Person>
-
<werte name="Ron" surname="Bolton" age="34" city="Madrid"/>
-
</Person>
-
<Person>
-
<werte name="Chris" surname="Summer" age="28" city="Rome"/>
-
</Person>
-
<Person>
-
<werte name="Anne" surname="Gordon" age="26" city="Munich"/>
-
</Person>
-
<Person>
-
<werte name="Mary" surname="Miller" age="30" city="Barcelona"/>
-
</Person>
-
</pulses>
PROCESSING CODE
-
import proxml.*;
-
XMLInOut xmlIO;
-
proxml.XMLElement myList;
-
int w = 800;
-
int h = 600;
-
boolean readData = true;
-
String name, surname, city, age;
-
PFont font;
-
void setup() {
-
size (w, h);
-
smooth();
-
font = createFont("Times", 60);
-
textFont(font);
-
xmlIO = new XMLInOut(this);
-
try {
-
xmlIO.loadElement("myData.xml");
-
}
-
catch (Exception e) {
-
xmlEvent(new proxml.XMLElement("myList"));
-
}
-
}
-
void draw() {
-
if (readData) readData();
-
}
-
void xmlEvent(proxml.XMLElement element) {
-
myList = element;
-
}
-
void readData () {
-
proxml.XMLElement[] allData = myList.getChildren();
-
for (int i = 0; i< allData.length; i++) {
-
proxml.XMLElement data = allData[i];
-
proxml.XMLElement param = data.getChild(0);
-
if (!param.getName().equals("werte")) continue; // Ignore unknown child
-
name = param.getAttribute ("name");
-
surname = param.getAttribute("surname");
-
age = param.getAttribute("age");
-
city = param.getAttribute("city");
-
textFont (font);
-
textSize(20);
-
fill (255);
-
text(name, 20+i*100, 100);
-
if (millis()> 3000) {
-
text(surname, 20+i*100, 125);
-
}
-
if (millis()>4000) {
-
text(age, 20+i*100, 150);
-
}
-
if (millis()>5000) {
-
text(city, 20+i*100, 175);
-
}
-
}
-
}
1