davmazo
Ex Member
proxml understanding troubles
Sep 2nd , 2009, 2:58am
Hi, I have troubles understanding this proxml library. I’m trying to load the data but it has a simple error that i don’t know why it's happening. error: ArrayIndexOutOfBoundsexception: Array index out of range: 0 The second question is, what is the method to save new “children” width attributes, Thanks for the help David code: //http://www.texone.org/proxml/ import proxml.*; // create the root element be specific where the class is proxml.XMLElement file = new proxml.XMLElement("position"); // create the color element proxml.XMLElement col = new proxml.XMLElement("color"); proxml.XMLElement poi = new proxml.XMLElement("point"); XMLInOut xmlIO; float x,y,r,g,b; int counter; void setup(){ size(400,400); smooth(); xmlIO = new XMLInOut(this); xmlIO.loadElement("position.xml"); } void draw(){ background(r,g,b); ellipse(x,y,20,20); } void xmlEvent(proxml.XMLElement element){ println(element.countAllChildren()); proxml.XMLElement[] child = element.getChildren(); for(int i = 0; i < child.length; i++){ //println(child); proxml.XMLElement culor = child[i].getChild(0); r = culor.getFloatAttribute("r"); g = culor.getFloatAttribute("g"); b = culor.getFloatAttribute("b"); proxml.XMLElement posi = child[i].getChild(1); x = posi.getFloatAttribute("x"); y = posi.getFloatAttribute("y"); } } void mouseReleased(){ x = mouseX; y = mouseY; // col.addChild(new proxml.XMLElement("point")); poi.addAttribute("x",mouseX); poi.addAttribute("y",mouseY); // make the color element a child of the root element file.addChild(poi,1); file.addChild(col,0); // create an XMLInOut object to format the elements XMLInOut xmlInOut = new XMLInOut(this); // and call saveElement. xmlInOut.saveElement(file, "position.xml"); } xml: <?xml version="1.0" encoding="ISO-8859-1"?> <position> <color b="255" g="100" r="55"/> <point x="205" y="228"/> </position>