XML edit in Processing 2.0
in
Programming Questions
•
5 months ago
Hi all,
Please help me out with editing XML file in processing 2.0.
I have a very basic question about editing xml file in processing 2.0. I'm having a trouble of editing a content of xml file even though it should be fairly simple thing to do. What I want to do is recoding mouseX postions with timestamps each time a mouse is clicked. The following code records only 1 click, but I want to record every clicks. I assume I should use array, but couldn't figure out how to do it.
I'm also wondering if it's possible to read, edit, and save a same XML file from "data" folder. The saved xml file is always stored in same location as processing file with current code. It would be ideal if I can work with a one file.
Thank you in advance!
// The following short XML file called "mammals.xml" is parsed // in the code below. It must be in the project's "data" folder. // <?xml version="1.0" encoding="UTF-8"?> // <positions> // <positionsX time="2013-05-15-18:54:40">69</positionsX> // </positions> XML xml; String mouseLocationsX; String mouseLocationsY; String timestamp; // got it from http://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/ void setup() { } void draw() { } void mousePressed() { if (mousePressed == true) { point (mouseX, mouseY); // make points based on mouse location print("mouseX: "); // print mouse X location print(mouseX); print(" "); timestampFunction (); mouseLocationsX = Integer.toString (mouseX); mouseLocationsY = Integer.toString (mouseY); xmlCreate(); } } void timestampFunction () {// time stamp function timestamp = year() +"-" + nf(month(), 2) + "-" + nf(day(), 2) + "-" + nf(hour(), 2) +":" + nf(minute(), 2) + ":" + nf(second(), 2); println(timestamp); } void xmlCreate () { xml = createXML("positions"); // parents XML positions = xml.addChild("positionsX"); // create a child called "position X" positions.setContent(mouseLocationsX); // x mouse location positions.setString("time", timestamp); // create attribute to child saveXML (xml, "positions.xml"); }
1