问题
This question is the continuation of this page
PROCESS: The process involved, Opening XML file and do some modification in specific nodes and save it back to another location.
PROBLEM FACING: While Saving after some modifications in XML, unsupported entity references like ö
converted into ö
. I want to retain the entity as it is in the source (ö
)
As ö
and ö
are same character but i need to retain as it is in source xml.
XML SOURCE
<?xml version="1.0" encoding="US-ASCII"?>
<heads>
<head type="TRANSFER">
<headtext xml:lang="ENG" original="y">My Name öis Sinthiya</headtext>
</head>
</heads>
EXPECTED OUTPUT
<?xml version="1.0" encoding="US-ASCII"?>
<heads>
<head type="TRANSFER">
<headtext xml:lang="ENG" original="y">My Name öis Sinthiya</headtext>
</head>
</heads>
GETTING RIGHT NOW
<?xml version="1.0" encoding="US-ASCII"?>
<heads>
<head type="TRANSFER">
<headtext xml:lang="ENG" original="y">My Name öis Sinthiya</headtext>
</head>
</heads>
My Code
string path = @"C:\work\myxml.XML";
string pathnew = @"C:\work\myxml_new.XML";
XmlDocument doc = new XmlDocument();
doc.Load(path);
using (var writer = XmlWriter.Create(pathnew, new XmlWriterSettings { Indent= true, Encoding = Encoding.ASCII }))
{
doc.Save(writer);
}
来源:https://stackoverflow.com/questions/37160364/handling-us-ascii-encoded-xml-with-unsupported-entity-reference