We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Problem writing XML in Windows with proXML
Page Index Toggle Pages: 1
Problem writing XML in Windows with proXML (Read 1212 times)
Problem writing XML in Windows with proXML
Nov 27th, 2006, 2:10am
 
Hi there,

I'm trying to use proXML in order to read/write xml files.  Reading is working fine but whenever I try to save a file likes this:

xmlIO.saveElement(new XMLElement("testElement"), "C:\\test.xml" );

I get the following error in Eclipse:

java.lang.NullPointerException
at proxml.XMLInOut.saveElement(XMLInOut.java:750)
at SevenUp.handleEvent(SevenUp.java:52)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at SpringGUI.SpringGUI$1.mousePressed(SpringGUI.java:246)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I:\DOCS\Eclipse\SevenUp\bin\data
You cannot write to this destination. Make sure destionation is a valid path

That last line about "cannot write to this destination" comes up with the same location no matter what i put into the documentURL parameter

I've tried changing the security settings on my computer to allow anyone to write to the C drive with no luck.  Any thoughts or suggestions are appreciated.

-Adam
Re: Problem writing XML in Windows with proXML
Reply #1 - Dec 8th, 2006, 8:54pm
 
It is not possible to write files to absolute urls so far. Try this:

xmlIO.saveElement(new XMLElement("testElement"), "test.xml" );

To save it to your data folder. I will add correct handling of absolute urls with the next update.
Re: Problem writing XML in Windows with proXML
Reply #2 - Mar 23rd, 2007, 1:43am
 
Hi, thanks for the response and sorry this took so long to reply, but I've been unsuccessful with the code you supplied as well.

After executing:

xmlIO.saveElement(new XMLElement("testElement"), "test.xml" );

I get the same error:

"I:\DOCS\Eclipse\SevenUp\bin\data
You cannot write to this destination. Make sure destionation is a valid path"

Even though I can paste that path into my Run prompt and it comes up fine.

I'm using Windows XP SP2 if that helps.  Any help would be appreciated.
Re: Problem writing XML in Windows with proXML
Reply #3 - Mar 23rd, 2007, 1:58am
 
I just stumbled upon something useful... I've been using Eclipse this whole time.  I tried running the same code from a Processing Sketch and it successfully wrote to "C:\Documents and Settings\Adam Ribaudo\My Documents\Processing\sketch_070322a\data"

So either there's a permissions problem for my I:\ drive orrrrr a problem in how I'm using Eclipse

In any case, it'd be *really* great to be able to save the file to an absolute URL <G>
Re: Problem writing XML in Windows with proXML
Reply #4 - Mar 23rd, 2007, 2:17am
 
One last post because I'm stumped... This is my project source in its entirety.  I've set my build path to the same place that Processing was able to write the XML.

-------------
import proxml.*;

public class XmlTest extends processing.core.PApplet {

private XMLInOut xmlIO;

public void setup()
{
frameRate(40);
  size(300, 150);
 
  xmlIO = new XMLInOut(this);
  xmlIO.saveElement(new XMLElement("ellipses"), "test.xml");
 
}
}

--------------


Returns:

"C:\Documents and Settings\Adam Ribaudo\My Documents\Processing\sketch_070322a\data
You cannot write to this destination. Make sure destionation is a valid path"
Re: Problem writing XML in Windows with proXML
Reply #5 - Oct 23rd, 2007, 11:34pm
 

does that mean that there is no way to save xml documents using proXML if i'm not using the library directly in the processing environment?

right now, i'm working in Eclipse.
Re: Problem writing XML in Windows with proXML
Reply #6 - Oct 24th, 2007, 12:08am
 
I actually got this working eventually and I feel like a chump for not updating the thread.  Doubley so because I don't have access to my source code right now.

The fix was very strange, I had to step through the code in debug mode and remove an entire if/else clause from the proXml component.  

I'll update this thread when I can with an answer but hopefully that will help.
Re: Problem writing XML in Windows with proXML
Reply #7 - Oct 24th, 2007, 2:03am
 
thanks for pointing this out, i didn't realize that the source code was included in the download.
it was a pretty simple hack:

File file = new File(filename);

though there's probably a safter way to do this that decides how to save the XML file depending on whether you're running the library in processing or in eclipse.
Re: Problem writing XML in Windows with proXML
Reply #8 - Apr 3rd, 2008, 1:07am
 
>File file = new File(filename);

Are you referring to line 1465 in XMLInOut or how did you do this hack? I'm in the same situation as you guys were in a half a year ago. Tried out hacking the XMLInOut class and recompiling but to no avail.
Re: Problem writing XML in Windows with proXML
Reply #9 - Apr 3rd, 2008, 11:35am
 
Just to answer my own question…

At around line 1465 in the XMLInOut class one can place the following hack code:

Code:

try {
//If the applet really is online

file = new File(pApplet.getClass().getResource("data/" + filename).toURI());

} catch (Exception e) {

//If the applet is used in Eclipse follow along the lines as if used in PDE

file = new File(pApplet.sketchPath + File.separator + "data", filename);

if (!file.exists()){

final String parent = file.getParent();

if (parent != null){

File unit = new File(parent);

if (!unit.exists())


unit.mkdirs();
}
}
}


This is probably not good practise to subvert a try block this way so if anybody has a better suggestion then let it be known.
Re: Problem writing XML in Windows with proXML
Reply #10 - Apr 3rd, 2008, 2:17pm
 
Not to downplay what Christian Riekoff did with ProXML, but I realized after a while that if you're using Eclipse anyway, you might as well use JDOM's XML implementation.  You get a wider support base, more thorough implementation, and no hiccups like the ones mentioned in this thread.

http://www.jdom.org/

Here's how I implemented saving my XML file with a Swing file chooser dialog:

try {
       

int returnVal = fc.showSaveDialog(this);
       

if (returnVal == JFileChooser.APPROVE_OPTION) {
                   org.jdom.Document doc = sevenUpPanel.toJDOMXMLDocument();
                   org.jdom.output.XMLOutputter fmt = new XMLOutputter();
                   java.io.File file = fc.getSelectedFile();
       


java.io.FileWriter fileWriter = new FileWriter(file);
       


fmt.output(doc, fileWriter);
       


fc.setCurrentDirectory(new File(file.getParent()));
       

}
           } catch (Exception ex) {
               ex.printStackTrace();
           }
Page Index Toggle Pages: 1