Search code examples
c#.netformattingxelement

How to get XElement.ToString() to omit the space before the self-closing slash?


By default, a self-closing tag is ToString()ed by XElement as follows:

<element />

<element attrib="value" />

However, I would like it without the extra space, i.e.

<element/>

<element attrib="value"/>

Is this possible with the XElement API?


Solution

  • I guess I’ll just do a string replace that will replace " />" with "/>".