Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove white spaces in XML Document in C#

Tags:

xml

c#-4.0

could anyone please help me on how to remove all the white spaces between XML tags as shown below:

<?xml version="1.0"?>
<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>

To:

<?xml version="1.0"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

Thank you heaps.

like image 283
Nil Pun Avatar asked Aug 03 '11 01:08

Nil Pun


1 Answers

You can use XLinq:

XElement.Parse(str).ToString(SaveOptions.DisableFormatting)
like image 79
SLaks Avatar answered Sep 28 '22 07:09

SLaks