Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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?

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 making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-11-30 10:36 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (769 votes), past polls