Results 1 to 5 of 5
  1. #1
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default XML file and HashMap

    Hello,

    I am working on an school assignment where I have a file. And I need to make a Java program to make it to an XML file. I almost have got the whole program working. But there is a little fault in it.

    Let's say this is the file I read in:
    >Monday
    First day of the week.
    Sunny day.
    >Tueseday
    Second day of the week.
    > Wendsday
    Almost until it is weekend again.
    Now busy with school.
    What I would like this part as:

    <day>Monday</day>
    <note>First day of the week.
    Sunny day.</note>
    <dayTueseday</day>
    etc. etc.

    At the moment I get back:

    <day>Monday</day>
    <note>First day of the week.</note>
    <note>Sunny day.</note>
    <dayTueseday</day>

    How do I solve this?
    I was thinking of HashMap.
    But can I also print this HashMap to the file I would like?
    Last edited by Lund01; 02-14-2011 at 10:30 AM.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    I think for note element you can use special separation character for example comma.
    Java Code:
     
    <day>Monday</day> 
    <note>First day of the week.;Sunny day.</note> 
    <dayTueseday</day>
    It is problems with HashMap I don't understand. You can use follow construction HashMap<String, List<String>>, where key - day, value list from note.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    Quote Originally Posted by Petr View Post
    I think for note element you can use special separation character for example comma.
    But how do I get the lines behind each other then?
    ; would not be even needed, becose I am also allowed to put these lines behind each other.

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    It is easy.
    Java Code:
    String value = "First day of the week.;Sunny day".
    String[] notes =  value.split(";");
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

Similar Threads

  1. Replies: 7
    Last Post: 12-08-2009, 07:17 PM
  2. HashMap Help
    By ScaryJello in forum New To Java
    Replies: 2
    Last Post: 04-15-2009, 09:18 AM
  3. Use Scanner to parse text file, adding to HashMap
    By JordashTalon in forum New To Java
    Replies: 0
    Last Post: 03-04-2009, 11:08 PM
  4. Hashmap - get key according to value
    By gtriant in forum New To Java
    Replies: 1
    Last Post: 12-15-2008, 02:29 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •