my dog learned polymorphism
The moose likes Java in General and the fly likes parsing plain file into html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "parsing plain file into html" Watch "parsing plain file into html" New topic

parsing plain file into html

Alex Dubin

Joined: Jul 04, 2005
Posts: 12
Hi guys,

I have a plan file that looks something like this:

This is how file looks in plain form and this is how html source code looks if I view the source code in the browser. Of course when I view the page in the browser it does not look like this because there is no spacing between columns and fields because there is no formatting.
Before I start to write my own parser, is there a parser out there already that can create an html file from this file using tables? I have one approach to replace all spaces with  , but it's not very elegant.
Any help is appreciated!


[ August 31, 2005: Message edited by: Alex Dubin ]
[ August 31, 2005: Message edited by: Alex Dubin ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
For your input I think this will be a manual process, not something you'll find already written.

HTML tables are the easiest way to align columns. So you want to generate:

How will you parse the id, name and phone out of each row of your file? It looks like they are in fixed positions so you can use substring. Does that give you some ideas?

I said there is probably not a general solution, but in fact Wiki sites render plain text into HTML for a living. Tables usually have some special delimiter to help:

Full Wiki markup is non-trivial but fascinating. Look at the source for Fit or Fitnesse for an education.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Alex Dubin

Joined: Jul 04, 2005
Posts: 12
thanks man!
This is exectly what I need!

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
The <PRE> tag is also meant to preserve the formatting of the text in between its opening and closing tags, so that might help you.
I agree. Here's the link:
subject: parsing plain file into html
It's not a secret anymore!