Solved

HTML spacing

Posted on 2002-05-30
9
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

739 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