how to convert a html file to an .xml one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to convert a html file to an .xml one
# 1  
Old 09-10-2008
how to convert a html file to an .xml one

Hii every one.
I have lots of .html files like:
Code:
<html>
<title>
</title>
<head>
</head>
<body>
<ul id="SummaryRatings">4 stars </ul>
<ul id="summaryList">
<p><b> Aurhor</b>
</p>
<p>wsfwfrfrtgretryetyrtyty</p>
</ul>
......
.......
</body>
</html>

And my final out put will be in...
Code:
<?xml.....>
<Review>
<rating>4stars>/rating>
<comment>
<author><b>Author</b></author>
<reviewcomment>wfegfgtgntjg;nrjtn</reviewcomment>
</comment>
</Review>

like that. So any idea how to doit??????? Smilie
# 2  
Old 09-10-2008
The usual way would be to create an XSLT stylesheet and use that with an XSLT processor to transform the HTML document into the required XML document.
# 3  
Old 09-10-2008
actually I have to write the code in shell script. So whow to do that....If possible please explaing the way..thanks in advance....
# 4  
Old 09-10-2008
Does "have to" mean "this is homework"?
# 5  
Old 09-11-2008
No its not a homework....... however if possible please suggest me the way ..
# 6  
Old 09-11-2008
Why do you have to do it using shell script?
# 7  
Old 09-12-2008
input(filename):
Code:
<html>
<title>
</title>
<head>
</head>
<body>
<ul id="SummaryRatings">4 stars </ul>
<ul id="summaryList">
<p><b>Author1</b>
</p>
<p>Author1 comments</p>
</ul>
<ul id="SummaryRatings">5 stars </ul>
<ul id="summaryList">
<p><b> Aurhor2</b>
</p>
<p>Author2 comments</p>
</ul>
</body>
</html>

output:
Code:
<?xml.....>
<Review>
<rating>4 stars </rating>
<comment>
<author><b>Author1</b></author>
<reviewcomment>Author1 comments</reviewcomment>
</comment>
</Review>
<Review>
<rating>5 stars </rating>
<comment>
<author><b> Aurhor2</b></author>
<reviewcomment>Author2 comments</reviewcomment>
</comment>
</Review>

code:
Code:
open(FH,"<filename");
while(<FH>){
	if(/Ratings/){
		@arr1=split("[<|>]",$_);
		push @rate,$arr1[2];
	}
	if(/<b>/){
		@arr2=split("[<|>]",$_);
		push @author,$arr2[4];
	}
	if(/<p>[^<]/){
		@arr3=split("[<|>]",$_);
		push @comment,$arr3[2];
	}
}
close(FH);
print "<?xml.....>\n";
for ($i=0;$i<=$#rate;$i++)
{
	print "<Review>\n";
	print "<rating>",$rate[$i],"</rating>\n";
	print "<comment>\n";
	print "<author><b>",$author[$i],"</b></author>\n";
	print "<reviewcomment>",$comment[$i],"</reviewcomment>\n";
	print "</comment>\n";
	print "</Review>\n";
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert content of file to HTML

Hi I have file like this: jack black 104 daniel nick 75 lily harm 2 albert 5 and need to convert it into the html table like this: NO.......name....family..... id 1...........jack.....black.....104 2..........daniel....nick.......75 3..........albert.................5 i mean... (5 Replies)
Discussion started by: indeed_1
5 Replies

2. UNIX for Dummies Questions & Answers

Convert Txt file to HTML table and email

Hi all I need help converting a text file into a html table in bash and I need to email this table. The text file looks like the below. Two columns with multiple rows. Top row being header. Application Name Application Status Application 1 Open Application 2 ... (2 Replies)
Discussion started by: hitmanjd
2 Replies

3. Shell Programming and Scripting

Convert text file to HTML tabular format.

Please provide script/commands to convert text file to HTML tabular format. No need of styles and colours, just output and a heading in table is required. Output file will be send via email and will be seen from outlook. (script required without using awk). output file content: (sar... (7 Replies)
Discussion started by: Veera_V
7 Replies

4. Shell Programming and Scripting

Need to convert output.txt into html file

I have output.txt file generated through shell scripts which need convert in tabular format using html can you please help me output.txt Token State Date1 Date2 Description Name 34567 open 27/06/13 28/06/13 ... (5 Replies)
Discussion started by: vijay_rajni
5 Replies

5. Shell Programming and Scripting

Script to convert csv file to html with good visibility

Hi, I have Below script which converts csv file to html succesfully.but the visiblity is simple in black n white. I want to have better visibilty of each columns in different colours(like green).As it is a Database report suppose some tablespace available space is less than 20% then it should... (7 Replies)
Discussion started by: sv0081493
7 Replies

6. Shell Programming and Scripting

Script to convert CSV file to HTML

Hi, I have made a a script which creates a csv file as daily database report However i want to covert that csv file to html because csv file does not have a good visibilty. So it is possible to have such csv to html coversion script. Your prompt help much appreciated. Thanks in advance (4 Replies)
Discussion started by: sv0081493
4 Replies

7. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies

8. UNIX for Dummies Questions & Answers

convert csv to html file

Hi All, I am new to this forum,not sure where to post this query...so posted here Kindly need any of your help on the below ------------ I am using shell scripting and trying to convert a csv file to html file... example.csv --------------- Name Country Age Sex Andy India 25 ... (4 Replies)
Discussion started by: sumithra
4 Replies

9. Shell Programming and Scripting

Convert comma text file to Column in html format

I am trying to generate a report with below file : File1 : EQADM,edrtere9-phys,8122caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere11-phys,8227caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere3-phys,822caef0,gpatmon,/bin/ksh,nuten Erick can you help me convert it to html and add... (9 Replies)
Discussion started by: sriram003
9 Replies

10. Shell Programming and Scripting

Need help to convert Flat file to HTML

Hello I need help to convert flat file data to HTML Table format. I am generating everyday Flat file and want to convert into HTML Table format. The format of my file is: version host Total YRS NO APPS PSD 10 Sun 30 2 4 6 7 and flat... (11 Replies)
Discussion started by: getdpg
11 Replies
Login or Register to Ask a Question