ericn
YaBB Newbies
Offline
Posts: 3
Problem accessing XML with applet-proXML
Mar 29th , 2010, 6:39pm
Hi everyone. I've been experimenting with proXML, hoping to create a persistent web applet. One problem I've run into though is that once you compile a sketch into an applet (just using the default ellipse example below), the XML file appears to be integrated into the java file. This prevents me from editing the XML file, so that the processing file is no longer persistent, as it was as a sketch. Is anyone aware of any work arounds to this problem? Either with proXML or the core XML library? Thanks for your time! // ellipse.xml code <?xml version="1.0"?> <ellipses> <ellipse> <position yPos="152" xPos="127"/> <size Xsize="61" Ysize="54"/> </ellipse> <ellipse> <position yPos="155" xPos="212"/> <size Xsize="33" Ysize="66"/> </ellipse> <ellipse> <position yPos="246" xPos="130"/> <size Xsize="65" Ysize="48"/> </ellipse> </ellipses> // ellipse.pde code import proxml.*; //to store the background after painting an ellipse PImage back; //xml element to store and load the drawn ellipses XMLElement ellipses; XMLInOut xmlInOut; int xPos = 0; int yPos = 0; void setup(){ size(400,400); smooth(); background(255); //load ellipses from file if it exists xmlInOut = new XMLInOut(this); try{ xmlInOut.loadElement("ellipse.xml"); }catch(Exception e){ //if the xml file could not be loaded it has to be created xmlEvent(new XMLElement("ellipses")); } } void xmlEvent(XMLElement element){ ellipses = element; initEllipses(); //initialise PImage for background back = new PImage(width,height); loadPixels(); back.pixels = pixels; } void draw(){ } //draw all ellipses saved in the xml file void initEllipses(){ ellipses.printElementTree(" "); XMLElement ellipse; XMLElement position; XMLElement size; for(int i = 0; i < ellipses.countChildren();i++){ ellipse = ellipses.getChild(i); position = ellipse.getChild(0); size = ellipse.getChild(1); ellipse( position.getIntAttribute("xPos"), position.getIntAttribute("yPos"), size.getFloatAttribute("Xsize"), size.getFloatAttribute("Ysize") ); } } void mousePressed(){ xPos = mouseX; yPos = mouseY; } void mouseDragged(){ background(back); ellipse(xPos,yPos,abs(xPos-mouseX),abs(yPos-mouseY)); } void mouseReleased(){ XMLElement ellipse = new XMLElement("ellipse"); ellipses.addChild(ellipse); XMLElement position = new XMLElement("position"); position.addAttribute("xPos",xPos); position.addAttribute("yPos",yPos); ellipse.addChild(position); XMLElement size = new XMLElement("size"); size.addAttribute("Xsize",abs(xPos-mouseX)); size.addAttribute("Ysize",abs(yPos-mouseY)); ellipse.addChild(size); xmlInOut.saveElement(ellipses,"ellipse.xml"); loadPixels(); back.pixels = pixels; }