regex - How do I remove all excess whitespace from an XML string using ColdFusion? -


i receive xml string client in format following...

<root>    <result success="1"/>    <userid>12345</userid>    <classid>56543</classid> </root> 

i need compress string down following...

<root><result success="1"/><userid>12345</userid><classid>56543</classid></root> 

so, of whitespace removed, except inside of tag (so space still exists between "result" , "success").

i have used replace statements remove line breaks, carriage returns, etc, can't remove spaces while ignoring spaces inside tags. there way use regular expression or other method accomplish this?

the below regx match spaces not within tags,

[\s]+(?![^><]*>) 

or

[\s]+(?![^><]*(?:>|<\/)) 

just replace matched spaces empty string.

demo

edit starts here

from comments - in context of coldfusion works this...

strclean = rereplace(stroriginal,"[\s]+(?![^><]*(?:>|<\/))","","all"); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -