Question: I'm having trouble reading an XML file and adding nodes to it. Well not exactly.. adding nodes works fine, but the source XML File contains some Lines containing `&quot;`

After Saving my xmlDocument those `&quot;` parts are converted to `"`

How can i prevent c# from converting `&quot;` to `"` because the application that loads the xml file needs those `&quot;` marks

Example Line:

`<item name="Description">DBName "xyz"</item>`

Answer: 
The consumer of the XML is definitely wrong if it requires to preserve the quote entities in XML texts. By default, the built-in writer replaces the unnecessary entities; however, you can override this behavior by implementing a custom writer:

```
public class PreserveQuotesXmlTextWriter : XmlTextWriter
{
    private static readonly string[] quoteEntites = { "&apos;", "&quot;" };
    private static readonly char[] quotes = { '\'', '"' };
    private bool isInsideAttribute;

    public PreserveQuotesXmlTextWriter(string filename) : base(filename, null)
    {            
    }

    public override void WriteStartAttribute(string prefix, string localName, string ns)
    {
        isInsideAttribute = true;
        base.WriteStartAttribute(prefix, localName, ns);
    }

    private void WriteStringWithReplace(string text)
    {
        string[] textSegments = text.Split(quotes);

        if (textSegments.Length > 1)
        {
            for (int pos = -1, i = 0; i < textSegments.Length; ++i)
            {
                base.WriteString(textSegments[i]);
                pos += textSegments[i].Length + 1;

                if (pos != text.Length)
                    base.WriteRaw(text[pos] == quotes[0] ? quoteEntites[0] : quoteEntites[1]);
            }
        }
        else base.WriteString(text);
    }

    public override void WriteString(string text)
    {
        if (isInsideAttribute)
            base.WriteString(text);
        else
            WriteStringWithReplace(text);
        isInsideAttribute = false;
    }
}

```

You can use it then even from an `XmlDocument` instance:

```
    XmlDocument xml = new XmlDocument();
    xml.Load(filename);
    // ...
    XmlWriter writer = new PreserveQuotesXmlTextWriter(filename);
    xml.Save(writer);

```
Thanks guys, i really didn't need to escape those quotes. The Problem is that document.save alters the xml output and so the target application can't properly read the xml.

Example:

`<profile>
 <list name="">
 <item name="FileVersion">0.88</item>
 <item name="ID">xyz</item>`

Turns into

`<profile>
 <list name="">
 <item name="FileVersion">0.88</item>
 <item name="ID">xyz</item>`

There are more spaces before the node

and if there are empty values

`<item name="Value"></item>`
turns into

`<item name="Value">
 </item>`