Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have XML in human readable format, eg:
...which I would like to compact to something similar to the following:<outermost> <innermost> <first>1</first> <second/> <third>These spaces are to be preserved.</third> </innermost> </outermost>
Only whitespace occuring within values needs to be preserved. Any whitespace which only separates tags from other tags can be removed.<outermost><innermost><first>1</first><second/> <third>These spaces are to be preserved.</third> </innermost></outermost>
I naively came up with the following regular expressions which takes care of most possibilities:
...but while I could easily see that there are more possibilities to consider (and these are not completely robust either...), I doubt I am the first to run into this problem.# <begin> <begin> $xml =~ s!(<\S+?>)\s+><\S+?>!$1$2!g; # </end> <begin> $xml =~ s!(</\S+?>)\s+><\S+?>!$1$2!g;
Is there a CPAN module or canned solution which deals with compacting XML?
Thanks.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: compacting XML?
by GrandFather (Saint) on Nov 30, 2011 at 02:38 UTC | |
Re: compacting XML?
by ikegami (Patriarch) on Nov 30, 2011 at 03:29 UTC | |
Re: compacting XML?
by choroba (Cardinal) on Nov 30, 2011 at 08:58 UTC | |
Re: compacting XML?
by Lotus1 (Vicar) on Nov 30, 2011 at 17:46 UTC | |
Re: compacting XML?
by sundialsvc4 (Abbot) on Nov 30, 2011 at 04:10 UTC | |
Re: compacting XML?
by TJPride (Pilgrim) on Nov 30, 2011 at 08:32 UTC | |
Re: compacting XML?
by Anonymous Monk on Nov 30, 2011 at 05:03 UTC | |
by Anonymous Monk on Nov 30, 2011 at 13:55 UTC |
Back to
Seekers of Perl Wisdom