Saving XML file to a web server
in
Programming Questions
•
2 years ago
Hi All,
This is driving me crazy. I'm writing a simple sketch to save RGB values to an xml file. I am using the proxml library. I have searched the forums and found several posts but none of them seem to have any code that I can use as a template. I have looked at the proxml site and it's not clear to me how to save to a web server. The file saves in my Data folder perfectly but as an applet nothing happens.
I have my folder permissions set to 777 and I have emptied the java cache. Not sure what I'm doing wrong. As usual, I'm sure it's something really silly.
Maybe I'm formatting the URL incorrectly?
Here is my code:
This is driving me crazy. I'm writing a simple sketch to save RGB values to an xml file. I am using the proxml library. I have searched the forums and found several posts but none of them seem to have any code that I can use as a template. I have looked at the proxml site and it's not clear to me how to save to a web server. The file saves in my Data folder perfectly but as an applet nothing happens.
I have my folder permissions set to 777 and I have emptied the java cache. Not sure what I'm doing wrong. As usual, I'm sure it's something really silly.
Maybe I'm formatting the URL incorrectly?
Here is my code:
- import proxml.*;
- PImage img;
- PFont f;
- void setup() {
- //set these to the size of the image
- size(500,650);
- f = loadFont("ArialMT-12.vlw");
- textFont(f,12);
- //this is the name of your image file saved in the data folder in your
- //processing folder see processing.org for help
- img = loadImage("RGBColormap.jpg");
- background(255);
- image(img,0,0);
- img.loadPixels();
- }
- void draw() {
- fill(0);
- text("Click Anywhere In The Color Image Above",150,530);
- if (mousePressed) {
- mousePress();
- }
- }
- void mousePress() {
- float r = (red(img.pixels[mouseX+mouseY*img.width]));
- float g = (green(img.pixels[mouseX+mouseY*img.width]));
- float b = (blue(img.pixels[mouseX+mouseY*img.width]));
- stroke(0);
- fill (r,g,b);
- rect (0,550,500,80);
- fill(0);
- text("This Is Your Color",200,595);
- // create the root element be specific where the class is
- proxml.XMLElement file = new proxml.XMLElement("root");
- // create the color element
- proxml.XMLElement col = new proxml.XMLElement("color");
- // add some attributes to it.
- col.addAttribute("r",(r));
- col.addAttribute("g",(g));
- col.addAttribute("b",(b));
- // make the color element a child of the root element
- file.addChild(col);
- // create an XMLInOut object to format the elements
- XMLInOut xmlInOut = new XMLInOut(this);
- // and call saveElement.
- xmlInOut.saveElement(file, "http://www.hunterjonakin.com/color/saving_color.xml");
- }

2