Can we force XmlWriter to issue <my-tag></my-tag> rather than <my-tag/>? Can we force XmlWriter to issue <my-tag></my-tag> rather than <my-tag/>? xml xml

Can we force XmlWriter to issue <my-tag></my-tag> rather than <my-tag/>?


This worked for me:

writer.WriteStartElement("my-tag");writer.WriteRaw(someString);writer.WriteFullEndElement();

WriteEndElement still self closed the tag


If you get the message Extension method can only be declared in non-generic, non-nested static class as the word this may be highlighted, simply create an extension class as shown below:

public static class Extension{    public static void WriteFullElementString(this XmlTextWriter writer, string localName, string value)    {        writer.WriteStartElement(localName);        writer.WriteRaw(value);        writer.WriteFullEndElement();    }}

Hope this proves useful :-)


Try this:

x.WriteStartElement("my-tag"); //Value of your tag is nullIf (<"my-tag"> == ""){  x.WriteWhitespace("");}else  x.WriteString(my-tag);x.WriteEndElement();