dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

XmlWriter should allow setting not to output space before closing slash for empty elements #109629

Open jez9999 opened 3 hours ago

jez9999 commented 3 hours ago

I have an XML document I want serialized by an XmlWriter, and I'm using this code:

        XmlWriter xw = XmlWriter.Create(sbXmlDoc, new XmlWriterSettings {
            Indent = true,
            IndentChars = "  ",
            OmitXmlDeclaration = true
        });

Unfortunately, this outputs spaces before closing slashes in empty elements (<element /> instead of <element/>) and I don't want the spaces there. XmlWriter (actually I'm getting a XmlWellFormedWriter) should provide an option not to output these spaces, or better yet, a custom callback for doing any extra formatting you want when each element is closed.

dotnet-policy-service[bot] commented 3 hours ago

Tagging subscribers to this area: @dotnet/area-system-xml See info in area-owners.md if you want to be subscribed.