Nil Pun
Nil Pun

Reputation: 17373

How to remove white spaces in XML Document in C#

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.

Upvotes: 5

Views: 8455

Answers (1)

SLaks
SLaks

Reputation: 887385

You can use XLinq:

XElement.Parse(str).ToString(SaveOptions.DisableFormatting)

Upvotes: 12

Related Questions