• 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

 
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 u all.

I wiould like to know how I can transform a text file into an xml. Is there any examples or tutorials that can help.

looking forward to hear from u all soon.

best regards
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are asking whether it is possible to transform text to XML using XSL... It is not possible to transform non-XML stuff to XML using XSL.

However if you want to transform XML to text using XSL... it is possible.
Take a look at the XSL tutorial on transforming XML to text at
XFront.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the text file have a structure that has to end up represented in the XML?
Presumably it does or you would just get a mess.
Therefore your first step is to figure out how to read the text file and parse out the structure. What needs to be recognized in the text to indicate the structure?

I have done a LOT of text to xml conversion utilities and those are the questions I always start with.
Bill
 
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.

--------------------

Abed 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,

Can anyone help me or give me advice solving this problem.

Thanks and best regards
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your parsing problem is too complex for java.util.StringTokenizer - java.io.StreamTokenizer has the capabilities you need.
Bill
 
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,

Thanks alot for your help. I solved it.

But i have another question:

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.
 
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

IS their anybody hear have a reply to my question.

Thanks and best regards
 
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 searched alot for SAX issues but I don't find what I need so clearly. So may be anyone can help me doing this.

What I need is just read data exist at text file using SAX and tranform it to XML file.

Thanks and best regards

Abed
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Abed Rabie:
Dear All,
Thanks alot for your help. I solved it.
But i have another question:

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.


SAX is not meant for reading text file and create xml.
Have you tried Williams suggestions ?
Could you please open a new thread on this topic so that you can get more attention.
 
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 Balaji Loganathan ,

I did it using JDom and read the text file and convert it to xml. This is well done with small text files but with huge one it causes memory problems so I red the data but need to build the xml using SAX not JDOM.

So please advice.

Thanks ane best regards
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic