DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Saving XML File - Error

  1. #1
    Join Date
    Jun 2006

    Saving XML File - Error

    I'm having problems saving an XML file.

    I have a JTree that I am changing to an object, then saving to XML via the XMLEncoder. This was working fine when I was just doing it locally, but now I'm doing it over the network.

    I send the JTree as an object over the network to the server. The server then saves it. Here is the code:

    	public void saveFile() {
    		try {
    			inStream = new ObjectInputStream(cSocket.getInputStream());
    			Object tree = fetchObject(inStream);
    			System.out.println("recieved >>" + tree);
    			String fileName = "example.xml";
    			File f = new File(fileName);
    			XMLEncoder e = new XMLEncoder(new BufferedOutputStream(
    					new FileOutputStream(f)));
    		} catch (IOException io) {
    			System.out.println("I/O error");
    	public static Object fetchObject(ObjectInputStream ois) throws IOException {
    		Object in = null;
    		try {
    			in = ois.readObject();
    			// Print data
    			System.out.println("Incoming packet --> " + in);
    		} catch (ClassNotFoundException cnf) {
    			System.out.println("unrecognized object type");
    		return in;
    The server gets the following error:

    at java.beans.XMLEncoder.writeExpression(Unknown Source)
    at java.beans.PersistenceDelegate.writeObject(Unknown Source)
    The resulting XML file is:
    <?xml version="1.0" encoding="UTF-8"?>
    <java version="1.5.0_06" class="java.beans.XMLDecoder">
    Where it should be much longer.

    Any ideas what I'm doing wrong?

  2. #2
    Join Date
    Jun 2006
    Answered my own question and figured I'd post it here. My error was in the client. You cannot export while a node in the JTree is selected so I had to use a method to unselect all, then save.

Similar Threads

  1. Why use XML?
    By Brian in forum XML
    Replies: 5
    Last Post: 01-10-2003, 09:39 PM
  2. (XML- - - )xml parsing error.
    By Manjunath in forum .NET
    Replies: 1
    Last Post: 08-22-2002, 08:40 PM
  3. Replies: 3
    Last Post: 09-03-2001, 04:48 AM
  4. Load problem
    By David E in forum XML
    Replies: 2
    Last Post: 05-29-2001, 12:52 PM
  5. Winsock32, Connect fails to connect to a peer
    By Chris.G in forum VB Classic
    Replies: 4
    Last Post: 11-13-2000, 04:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center