Hey all I'm trying to create an xml file of mouse points on keypressed. I've got the xml writing and printing out the root element properly in processing but it's not properly writing to a file it only writes the first point in the file. What am I missing. Any ideas on what might be missing? I havent dealt with writing xml files in processing in a while so it may be something simple and stupid i'm missing.
heres the code I was working with. I'm working in Eclipse btw:
- package writetofile;
- import processing.core.*;
- import processing.xml.*;
- import java.io.PrintWriter;
- public class WriteToFile extends PApplet {
- static final long serialVersionUID = 289273923L;
- PrintWriter pw;
- XMLElement root = new XMLElement("points");
- public void setup() {
- pw = createWriter("data/text.xml");
- }
- public void draw() {
- if(keyPressed){
- //writeLine(new PVector(mouseX, mouseY));
- }
- }
- public void writeLine(PVector pt){
- XMLElement xml = new XMLElement("pt");
- xml.setFloat("x", pt.x);
- xml.setFloat("y", pt.y);
- root.addChild(xml);
- root.write(pw);//where the problem is. Its only writing the first child element of pt in to the file.
- pw.flush();
- pw.close();
- println(root);;// this prints out the whole root element with all the children that have been added thus far
- }
- public void keyPressed(){
- writeLine(new PVector(mouseX, mouseY));
- }
- }
Thanks in advance!
Kobby
1