Solved

HTML spacing

Posted on 2002-05-30
9
178 Views
Last Modified: 2010-03-05
I have an html document and I would like to remove all of the spaces (blank lines).  Theres only one catch I want the body tag spaces not to be touched. Leaving the spaces in between the paragraphs alone.

I.e.
<html>

<head>


<title> This is my Web page

</title>



<head>

<body>
The paragraphs in this script should not be touched.

I would like the spacing to be the same.

Can this be done.
</body>

</html>

Should look like this:

<html>
<head>
<title> This is my Web page
</title>
<head>
<body>
The paragraphs in this script should not be touched.

I would like the spacing to be the same.

Can this be done.
</body>
</html>
0
Comment
Question by:kennybud416
9 Comments
 
LVL 3

Expert Comment

by:tgoetze
ID: 7045715
$removing_on = 1;
while(<>) {
    $removing_on = 0 if (/\<body\>/);
    print unless ($removing_on && /^$/);
}
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 7045972
$_ = join'',<>;
s/\n\s*\n|(<body>.*?<\/body>)/${[$1,"\n"]}[!$1]/sgi;
print;
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7046151
what difference does it make?

all browsers ignore white spaces.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Expert Comment

by:tgoetze
ID: 7046337
ozo,

Very nice, now if you could just obfuscate it a little, maybe you could win a contest. :)

Matching section seems straightforward enough. Is that an array of hashes in the replacement section?
If so, when does it get built?
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7046343
RE:
what difference does it make?
all browsers ignore white spaces.
0
 
LVL 3

Expert Comment

by:tgoetze
ID: 7046347
lexxwern,

Maybe it is not being viewed in a browser.
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7046399
could be, but i'ld want kennybud416 to answer this question.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 7047248
actually one time I read a book that reccomended removing all white space to ...get this...

decrease the time to load page.

ha ha.

yeah, this is true, it does have a good effect, but ...well, it's way to anal for me.

0
 

Author Comment

by:kennybud416
ID: 7051561
The xml file runs through a perl script.  This perl scirpt put each field(tag) into the orcale database. Each tag is assigned a certain number of chacters in the database.  if there are too many spaces in between two tags the tags are rejected and thrown away.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sort hash by values desc 2 193
How to delete rows in a file based on the file name. 5 60
Migrate OTRS to newest version. 1 326
Log File Creation with Header and Footer 17 93
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question