Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: compacting XML?

by choroba (Canon)
on Nov 30, 2011 at 08:58 UTC ( #940798=note: print w/ replies, xml ) Need Help??


in reply to compacting XML?

I usually use XML::XSH2 for XML manipulation. This code removes all the text that is only whitespace (which is not exactly the same as your specification), but the output is the same as of the other solutions.

for //text() { if xsh:match(., '^\s+$') set . '' }
Update: This should delete only whitespace that has an element sibling:
for //text() { if ((following-sibling::* or preceding-sibling::*) and xsh:match(. +, '^\s+$')) set . '' }


Comment on Re: compacting XML?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2015-07-07 11:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls