Your code does what you tell him, I'm afraid.
xmlWriter.WriteStartElement("element"); //<element> xmlWriter.WriteString("\r\na\r\n"); //newline, directly followed by 'a' xmlWriter.WriteEndElement(); //</element>
If you need indentation, you will have to write this in your code, for example
xmlWriter.WriteString("\r\n\ta\r\n");
The problem with this approach is that if your <element> already indented, it will ruin the indent - your 'a' will still be indented with only one tab.
So, you can somehow calculate the indentation, and write the appropriate number of tabs, or you will go with the whole element in one line
<element>a</element>
This is definitely understandable, but it may seem strange when "a" becomes a very long text.
source share