Decimal entities replaced by Hexadecimal entities in C# XML

159 views Asked by At

I've following decimal entities 	 and 
 for TAB and NEWLINE characters in attributes in XML file. After processing the file and saving, above decimal entities are replaced with its hexadecimal equivalents i.e 	 and 
 respectively.

Content in file before processing,

<car id="wait for the signal &#10;&#10; then proceed &#9;">

Content after processing the file,

<car id="wait for the signal &#xA;&#xA; then proceed &#x9;">

XmlWriter code block i used,

XmlWriterSettings xmlWriterSettings = new XmlWriterSettings
{
    Indent = true,
    Encoding = encoding,
    NewLineHandling = NewLineHandling.Replace
};
XmlDataDocument xmlDataDocument = new XmlDataDocument
{
    PreserveWhitespace = true
};
xmlDataDocument.LoadXml(xmlString);
using (XmlWriter writer = XmlWriter.Create(filepath, xmlWriterSettings))
{
    if (writer != null)
    {
        xmlDataDocument.Save(writer);
    }
}

Note: I'm aware that having either decimal or hexadecimal entity in XML file, both case should work. But i'm specifically looking for solutions to retain the same decimal entities after processing the file.

any help one this is much appreciated.

0

There are 0 answers