Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

Decimal entities replaced by Hexadecimal entities in C# XML

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.

question from:https://stackoverflow.com/questions/65879535/decimal-entities-replaced-by-hexadecimal-entities-in-c-sharp-xml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...