this is the code i use to parse the xml file written above in my last post. I used the piece of code you gave me as well....
----------------------------------------------
Code:
import proxml.*;
ArrayList personList;
float height_p;
float width_p;
StringBuffer buffer_height;
StringBuffer buffer_width;
String string_height;
String string_width;
int int_height;
int int_width;
int count;
PImage back;
XMLElement Data;
XMLInOut xmlInOut;
int posX = 10;
int posY = 10;
void setup() {
size (800,450);
noStroke();
smooth();
personList = new ArrayList();
buffer_height = new StringBuffer();
buffer_width = new StringBuffer();
xmlInOut = new XMLInOut(this);
try{
xmlInOut.loadElement("datatable1.xml");
}
catch(Exception e){
//if the xml file could not be loaded it has to be created
xmlEvent(new XMLElement("datatable"));
}
}
void draw(){
}
void keyReleased () {
if (keyCode == 10) {
count ++;
}
if (keyCode == 8 ) {
if (buffer_height.length() > 0) {
buffer_height.deleteCharAt (buffer_height.length()-1);
}
}
if (count == 0 && key != ENTER) {
buffer_height.append(key);
string_height = buffer_height.toString();
int_height = int(string_height);
}
if (count == 1 && key != ENTER) {
buffer_width.append(key);
string_width = buffer_width.toString();
int_width = int(string_width);
}
if (count == 2) {
analyze();
}
}
void analyze () {
rect (posX,posY, int_width, int_height);
count = 0;
posX += int_width+10;
save();
setup();
}
void xmlEvent(XMLElement element){
Data = element;
initData();
//initialise PImage for background
back = new PImage(width,height);
loadPixels();
back.pixels = pixels;
}
class Person {
float height_p;
float width_p;
Person (float height_p, float width_p) {
this.height_p = height;
this.width_p = width;
}
}
void initData(){
XMLElement value;
XMLElement height;
XMLElement width;
for(int i = 0; i < Data.countChildren();i++){
value = Data.getChild(0);
height = value.getChild(0);
width = value.getChild(1);
personList.add(new Person (width_p,height_p));
}
}
void save(){
XMLElement value = new XMLElement("person");
Data.addChild(value);
XMLElement height = new XMLElement("height");
height.addAttribute("value_height", string_height);
value.addChild(height);
XMLElement width = new XMLElement("width");
width.addAttribute("value_width", string_width);
value.addChild(width);
xmlInOut.saveElement(Data,"datatable1.xml");
}
----------------------------------------------
so i now have to read the data out of the xml file into an ArrayList?
As you posted?
Hmm..and how can I use the comparator class now?
Thanks for helping me, I hope my code is not too confusing...