Solved

HTML spacing

Posted on 2002-05-30
9
179 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

821 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