Remove whitespace in self closing tags when writing xml document

Viewed 6515

When writing out an xml document I need to write all self closing tags without any whitespace, for example:

<foo/> 

instead of:

<foo />

The reason for this is that a vendor system that I'm interfacing with throws a fit otherwise. In an ideal world the vendor would fix their system, but I don't bet on that happening any time soon. What's the best way to get an XmlWriter to output the self closing tags without the space?

My current scheme is to do something like:

return xml.Replace(" />", "/>");

Obviously this is far from ideal. Is it possible to subclass the XmlWriter for that one operation? Is there a setting as part of the XmlWriterSettings that I've overlooked?

3 Answers
Related