Results 1 to 10 of 10
  1. #1
    er_zhong is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default [SOLVED] jTextPane to xml

    Hi!

    I have a question, how to write the text and pictures from a JTextPane into a XML document?!

    I can save the text and pictures from the JTextPane into a document but it not works with XML document:

    private void doSave(File file) {
    FileOutputStream fous = null;
    {
    ObjectOutputStream oos = null;
    try {
    fous = new FileOutputStream(file);
    oos = new ObjectOutputStream(fous);
    oos.writeUnshared(jTextPane_weather.getStyledDocum ent());
    oos.flush();
    } catch (IOException ex) {
    //...
    } finally {
    try {
    fous.close();
    } catch (IOException ex) {
    //...
    }
    try {
    oos.close();
    } catch (IOException ex) {
    //...
    }
    }
    }
    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    My suggestion is, first of all try to workout a simple application to write some data into a XML file in Java. Read more about javax.xml.parsers API in Java.

  3. #3
    er_zhong is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default

    thanks!

    I can write the XML.

    But I can't write the "objects" into XML, for XML is plain text.

    I just want to save the things from NINE jTextPanes into one file.

    Without XML, how can I save them and parse the file?!

  4. #4
    er_zhong is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default

    I'm really sorry.

    I'm just new to java, and learned that .java-forums.org and forums.sun.com are both big java communities.

    I have no idea where should I ask the question, so I post both.

    If I have wasted your time, I'm really sorry and please accept my apology!

    I will discuss the question:
    "forums.sun.com/thread.jspa?threadID=5380152&tstart=0"

    Thank you!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by er_zhong View Post
    I'm really sorry.

    I'm just new to java, and learned that .java-forums.org and forums.sun.com are both big java communities.

    I have no idea where should I ask the question, so I post both.

    If I have wasted your time, I'm really sorry and please accept my apology!

    I will discuss the question:
    "forums.sun.com/thread.jspa?threadID=5380152&tstart=0"

    Thank you!
    Cross-posting is not good. People can avoid answering to your question, a lot.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by er_zhong View Post
    thanks!

    I can write the XML.

    But I can't write the "objects" into XML, for XML is plain text.

    I just want to save the things from NINE jTextPanes into one file.

    Without XML, how can I save them and parse the file?!
    Search the web, search our forum. You can find a lot. Here is one of them I've found on the web. Not exactly what you want, but if you can have an idea.

    Serializing Java Objects as XML

  7. #7
    er_zhong is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default

    Thank you very much!

    "Cross-posting is not good."I will remember that!

    I will discuss the problem at //forums.sun.com/forum.jspa?forumID=31&start=0

    and also post the solution here.

    Thanks for your suggestion, and it's my honor if you can join the discussion there!

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  9. #9
    er_zhong is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default

    ^o^ thank you anyway!

    E-mail:shun.ps@gmail.com

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Clipboard and jTextPane
    By Gudradain in forum AWT / Swing
    Replies: 11
    Last Post: 01-04-2009, 11:08 PM
  2. StyledDocument for JTextPane
    By nadia in forum AWT / Swing
    Replies: 2
    Last Post: 12-28-2008, 02:41 AM
  3. JTextPane with servlets
    By kinabaloo in forum Advanced Java
    Replies: 2
    Last Post: 07-11-2008, 06:32 AM
  4. JTextPane Styles Example
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:48 PM
  5. Transparent JTextPane
    By Ada in forum AWT / Swing
    Replies: 1
    Last Post: 05-31-2007, 09:50 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
  •