Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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>

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2016-10-28 01:19 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (373 votes). Check out past polls.