XML file creation using XDocument in C#

前端 未结 2 654
故里飘歌
故里飘歌 2020-11-29 18:03

I have a List \"sampleList\" which contains

Data1
Data2
Data3...

The file structure is like

<         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 18:30

    Using the .Save method means that the output will have a BOM, which not all applications will be happy with. If you do not want a BOM, and if you are not sure then I suggest that you don't, then pass the XDocument through a writer:

    using (var writer = new XmlTextWriter(".\\your.xml", new UTF8Encoding(false)))
    {
        doc.Save(writer);
    }
    

提交回复
热议问题