Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 chanting in the Monastery: (11)
As of 2014-08-22 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (164 votes), past polls