[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HTML spacing

Posted on 2002-05-30
9
Medium Priority
?
184 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 85

Accepted Solution

by:
ozo earned 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans
Suggested Courses

834 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