Inward_Spiral
asked on
Can I use regex to strip out xml whitespace?
Hello all,
I'm doing a lot of work with XML, but there are some cases where it would be faster to just deal with the XML data as a string.
Changing it to a string isn't a problem, but there's some whitespace that gets added in between the nodes that's throwing me off.
Can I structure a regular expression that can strip out the whitespace in between the nodes of the string?
I've done simple expressions with 'g' for replace-all commands, but nothing quite like this.
Any assistance would definitely be appreciated.
Thanks!
I'm doing a lot of work with XML, but there are some cases where it would be faster to just deal with the XML data as a string.
Changing it to a string isn't a problem, but there's some whitespace that gets added in between the nodes that's throwing me off.
Can I structure a regular expression that can strip out the whitespace in between the nodes of the string?
I've done simple expressions with 'g' for replace-all commands, but nothing quite like this.
Any assistance would definitely be appreciated.
Thanks!
ASKER
JavaScript, actually.
I'm pulling in some XML text from the server via AJAX, which sometimes has whitespace (spaces, carriage returns, etc.), and can come in like this sometimes:
<RootNode>
<ParentNode>
<ChildNode>Text</ChildNode >
</ParentNode>
</RootNode>
I'd like to strip the string of all spacing between the "><" brackets:
<RootNode><ParentNode><Chi ldNode>Tex t</ChildNo de></Paren tNode></Ro otNode>
Does that help?
Thanks.
I'm pulling in some XML text from the server via AJAX, which sometimes has whitespace (spaces, carriage returns, etc.), and can come in like this sometimes:
<RootNode>
<ParentNode>
<ChildNode>Text</ChildNode
</ParentNode>
</RootNode>
I'd like to strip the string of all spacing between the "><" brackets:
<RootNode><ParentNode><Chi
Does that help?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Bill, that was exactly what I needed.
No problem, thanks for the points
Cheers,
-Bill
Cheers,
-Bill
Perl:
$data =~ s/\s+//g;
Python:
data = data.replace( ' ', '');
Java:
str = new String( str.replaceAll( "\s+", '' );