DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Posts
    2

    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:

    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)));
    			e.flush();
    			e.writeObject(tree);
    			e.close();
    		} catch (IOException io) {
    			System.out.println("I/O error");
    		}
    	}
    Code:
    	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
    Posts
    2
    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, 08: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, 03:16 PM

Bookmarks

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links