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.
In reply to compacting XML? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |