Results 1 to 2 of 2

Thread: [java] write and read from file a dictionary

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default [java] write and read from file a dictionary

    Hello,
    I have a class Dictionary with "Word" and its frequency into a document. I wrote to file all these informations as xml. I wrote the file using .write method eg: out.write("<dic>\r\n"); etc. Is this way to write XML good?
    The file will be:
    Qt Code:
    1. <dic>
    2. <word freq="0.000002"> Hello </word>
    3. //all word
    4. </dic>
    To copy to clipboard, switch view to plain text mode 
    is it better do in this way: ??
    Qt Code:
    1. <dic>
    2. <word>
    3. Hello
    4. <freq>
    5. 0.000002
    6. </freq>
    7. </word>
    8. //al word
    9. </dic>
    To copy to clipboard, switch view to plain text mode 
    What will be the better?
    In the end I have to read it and fill my structures (basically my class Dictionary).
    Furthermore: is all this approach ok?

    thanks,
    Regards

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [java] write and read from file a dictionary

    Such questions are hard to answer ;-)

    The second variant allows you more flexibility if ever you should feel the need to add more details to the "freq".
    The first is simpler, on the other hand. I'd go with the first one (attribute) here.

    And, yes, generating xml in that way is perfectly ok - esp. for such trivial structures.
    If you had some generic tree structure, you could of course write a generic "toXml" traversal function... but since you have nothing of the kind, you would save no work if you were to generate some intermediate structure first.

    Maybe, if your attributes get more numerous, you might want to introduce some helper class (I am sure there exists something like that in the Java universe), and create a tag; call some addAttribute() methods and finally print that tag (maybe with a passed indentation or so).

    Don't overdo it, though. Otherwise you end up coding a xml DOM. (And if you want to use one, just grab one of the existing ones.)

    HTH

Similar Threads

  1. file read & write help....
    By aj2903 in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2008, 11:58
  2. [Java] read and write a file
    By mickey in forum General Programming
    Replies: 3
    Last Post: 22nd June 2008, 10:43
  3. structures to a file (read and write)
    By baray98 in forum Qt Programming
    Replies: 5
    Last Post: 10th February 2008, 20:12
  4. How to open a file in Read Write mode
    By merry in forum Qt Programming
    Replies: 13
    Last Post: 16th November 2007, 14:40
  5. Read \Write Excel File using Qt
    By xingshaoyong in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 22:07

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.