Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: compacting XML?

by TJPride (Pilgrim)
on Nov 30, 2011 at 08:32 UTC ( #940793=note: print w/ replies, xml ) Need Help??


in reply to compacting XML?

This should work as long as you don't care about retaining empty strings (<tag> </tag>) and as long as the content itself doesn't contain the < character. A good XML parser will of course also work, but if your data is simple, there may be no need.

use strict; use warnings; my $xml = join '', <DATA>; while ($xml =~ s/(<\/?.*?>)\s+(<\/?.*?>)/$1$2/sg) {} print $xml; __DATA__ <outermost> <innermost> <first>1</first> <second/> <third>These spaces are to be preserved.</third> </innermost> </outermost>


Comment on Re: compacting XML?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://940793]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-07-14 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls