• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transform text file to xml file

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

Good luck for you all

I'd like to ask about a link or papers that help me in transforming data exist in text file into xml format according to certain criteria in a property file.

looking forward to hear from u soon

Thanks & best regards

Abed
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Rabie. I know this is coming rather late given that you have over 40 posts, but you need to change your displayed name to conform to our
naming policy. In short, your name must be a first name and last name, separated by a space and not obviously fake.
I don't know of any resources that describe exactly what you are looking for. You can read about Java IO here and the Java API's for XML here. XML is plain text, so it may be enough to read in your data according to your properties file, wrap the data with the appropriate XML tags and write it out without using the XML-specific API's.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post a short example of input text and output XML? I'm not quite clear on what you want to accomplish. thanks!
 
Abed Rabie
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friend,

The text file is formatted as follows:

"PLAYER1","page2","page2, aymanNewT.sca",02/01/2005,12:46:12,02/01/2005,12:46:30
"PLAYER1","page3","page3, aymanNewT.sca",02/01/2005,12:46:30,02/01/2005,12:46:38
"PLAYER1","page2","page2, aymanNewT.sca",02/01/2005,12:46:38,02/01/2005,12:46:51
"PLAYER1","page2","page2, aymanNewT.sca",02/01/2005,12:46:51,02/01/2005,12:46:52
"PLAYER1","page2","page2, aymanNewT.sca",02/01/2005,12:46:52,02/01/2005,12:46:53
"PLAYER1","page2","page2, aymanNewT.sca",02/01/2005,12:46:53,02/01/2005,12:46:55
"PLAYER1","page2","page2, aymanNewT.sca",02/01/2005,12:46:55,02/01/2005,12:47:00
"PLAYER1","page2","page2, aymanNewT.sca",02/01/2005,12:47:00,02/01/2005,12:47:03
"PLAYER1","kalaa 3","kalaa 3, aymankalaa.sca",02/01/2005,13:28:14,02/01/2005,13:29:01
"PLAYER1","kalaa 3","kalaa 3, aymankalaa.sca",02/01/2005,13:29:02,02/01/2005,13:29:02
"PLAYER1","kalaa 3","kalaa 3, aymankalaa.sca",02/01/2005,13:29:02,02/01/2005,13:29:03
"PLAYER1","kalaa 3","kalaa 3, aymankalaa.sca",02/01/2005,13:29:03,02/01/2005,13:29:05
"PLAYER1","kalaa 3","kalaa 3, aymankalaa.sca",02/01/2005,13:29:05,02/01/2005,13:29:06


* Each line is considered a new record.

* Data elements are separated by a comma (,).

Note: if a comma found inside a double quoted string it is not considered a separator

* The elements names from left to right are:

�The player name

�The page name

�The script name

�The Start Date

�The Start Time

�The End Date

�The End Time

so can u help me reformatting it to a xml one according to the predefined criteria.

Mohamed Rabie
 
Abed Rabie
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I'm in bad need for help. Cam anyone suggest a solution for me please or recommend a good tutorial for this.

best regards
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a couple problems here. First is reading and parsing comma separated values. Google for "java csv parser" and find many packages you can use to do that. If you really want to (or have to) write your own code, you might browse the docs and get some ideas about what has to be done. This seems to be a fairly common problem, so isolate this code to a set of classes you can reuse another day.

The second problem is generating XML. Let's say your parser puts the fields in to an array. You can generate a big String pretty easily:

You could also create a DOM but that's quite a bit trickier.

Any of that sound useful? Try putting some code together and let us see what you come up with.
 
Abed Rabie
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Friend,

this solution either i use dom or jdom.

thx
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With JDOM, its easy. Just create a Document object and add content to it (i.e. Element objects), then use XMLOutputter to write to a File.

The JDOM website has some good tutorials.
 
Abed Rabie
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friend,

Thanks alot for your care and help. I solved it.

Best regards

Abed
 
Abed Rabie
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I have another question and looking forward for quick reply please.

Can I use SAX to convert text file to XML file or SAX only used to read from xml not text files ??

Thanks alot for u all

looking to hear from u soon.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SAX is used to parse XML documents.
 
reply
    Bookmark Topic Watch Topic
  • New Topic