How to remove invisible junk characters from a XML file

后端 未结 2 1112
-上瘾入骨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);
    }
    
    0 讨论(0)
  • 2021-01-26 10:11

    That might be the UTF-8 byte-order mark. Many text editors (for example Notepad++ and jEdit) allow you specify whether the BOM should be written for UTF-8 or not. With Windows Notepad your only option is to save the file as ANSI.

    0 讨论(0)
提交回复
热议问题