LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-22-2005, 02:22 PM   #1
osio
Member
 
Registered: Jun 2005
Posts: 70

Rep: Reputation: 15
text to xml to html


I would like to write a text file with entries like:

title: task 1
date: 22/7/05
content: do this and that

title: task 2
date: 22/7/05
content: then this and also that

and keep on editing and adding entries and then convert it into a xml file and finally into a html one. The html files would convert the fields above to something like:

<h1>task 1</h1>
<h2>22/7/05</h2>
<p>do this and that</p>

I'm not familiar with perl or phyton but can use scripts based on them and I can cope with a little of bash scripting.
Is there any tool or program to do this?

Last edited by osio; 07-22-2005 at 02:24 PM.
 
Old 07-22-2005, 06:19 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Perl ships with a module called CGI that semi-automates the process of writing out HTML. Type perldoc CGI into a terminal for more detailed instructions. (And perldoc perl if you want to start learning Perl programming!)

If you want to write (or parse) XML in some non-HTML format, I would use the XML::Twig Perl module. To install it, you can do this:
Code:
sudo perl -MCPAN -e shell
(the first time you run this, you will get a prompt asking if you're ready for manual configuration; type no)
cpan> install XML::Twig;
(wait until it's installed, then press Ctrl+D to exit back to the shell)
Also perldoc XML::Twig should give you some documentation.
 
Old 07-28-2005, 11:45 AM   #3
osio
Member
 
Registered: Jun 2005
Posts: 70

Original Poster
Rep: Reputation: 15
Thank you rjlee, I'll print and read the perldoc CGI, although it looks a bit too advanced for me.
 
Old 07-28-2005, 11:49 AM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
If your entries are stricly in the format from the example you posted
just some sed commands should be efficient though
 
Old 07-28-2005, 12:16 PM   #5
osio
Member
 
Registered: Jun 2005
Posts: 70

Original Poster
Rep: Reputation: 15
replacements with sed

All right, so you mean something like
sed -i -e 's/^title/$\<\\h1\>\ -e 's/title:/\<h1\>/' ..........?
Then I insert a xml header and I'm done?
 
Old 07-28-2005, 12:39 PM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You could use :
Code:
sed -i -e 's#title: \(.*\)#<h1>\1</h1>#g' \
-e 's#date: \(.*\)#<h2>\1</h2>#g' \
-e 's#content: \(.*\)#<p>\1</p>#g' filename
Note that -i overwrite your original file, I don't know if it is what you want
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to convert text(html) back to html. d1l2w3 Linux - Software 4 04-08-2005 08:16 PM
XSL need help translating XML to html hyperlink qwijibow Programming 1 03-09-2005 04:36 PM
html, xml, php, mysql atheist Programming 8 06-07-2004 01:28 PM
How can I transform XML into HTML on bash? pedrosan Linux - Newbie 0 04-22-2004 02:37 AM
XML can't store HTML?!? Travis86 Programming 10 08-25-2003 07:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration