How to remove invisible junk characters from a XML file

后端 未结 2 1136
-上瘾入骨i
-上瘾入骨i 2021-01-26 09:08

I want to read some xml files.

when i am opening these files with notepad/wordpad/MS Word or any Browser, it is opening in its original form.But when i tried to execute

2条回答
  •  青春惊慌失措
    2021-01-26 10:07

    Sure sounds like a byte-order mark. Your question is unclear, but if actually do need to write these files from C# without a byte-order mark, you can specify this by passing false to the UTF8Encoding constructor:

    XmlDocument xmlDoc = your_xml_document;
    using (TextWriter writer = new StreamWriter(output_filename, new UTF8Encoding(false))
    {  
        xmlDoc.Save(writer);
    }
    

提交回复
热议问题