I found this question that is similar to mine, I am also signing a XML document with a library that uses XmlDocument and I am having the same problem.
My question now is why and if possible, how to avoid it. I am not even using the Load method but replacing InnerXML trying to avoid the parser, with no result.
string XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<HtmlEncode>" +
"<accents>" + HttpUtility.HtmlEncode("áéíóúÁÉÍÓÚ") + "</accents>" +
"<tilde>" + HttpUtility.HtmlEncode("ñÑ") + "</tilde>" +
"<specialChar>" + HttpUtility.HtmlEncode("&") + "</specialChar>" +
"<text>" + HttpUtility.HtmlEncode("Pérez & Compañía") + "</text>" +
"</HtmlEncode>";
txtOriginal.Text = XML;
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
xDoc.InnerXml = XML;
txtEncoded.Text = xDoc.InnerXml;
original XML
<?xml version="1.0" encoding="UTF-8"?>
<HtmlEncode>
<accents>áéíóúÁÉÍÓÚ</accents>
<tilde>ñÑ</tilde>
<specialChar>&</specialChar>
<text>Pérez & Compañía</text>
</HtmlEncode>
XML after the parser
<?xml version="1.0" encoding="UTF-8"?>
<HtmlEncode>
<accents>áéíóúÁÉÍÓÚ</accents>
<tilde>ñÑ</tilde>
<specialChar>&</specialChar>
<text>Pérez & Compañía</text>
</HtmlEncode>
Can anyone point me in the right direction?
For now, I am manually replacing the accents and tildes with the characters without them but I would rather have the correct ones encoded.