|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dirty chars with save methodI'm trying to create an xml doc using the XMLDocument object (Framework 1.1) to export data to an application. The file is created using this syntax: string newDocumentText = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"; xmlDoc = new XmlDocument(); xmlDoc.LoadXml(newDocumentText); After that, I append several nodes to the document using the AppendChild method and create the file with the XMLDocument Save Method. xmlDoc.Save(FileName); Everything seems ok but, if I try to open the file with a byte editor, I noticed that there are some dirty chars at the beginning of the file: <?xml version="1.0" encoding="UTF-8"?> .... These chars are not visible within Internet Explorer, notepad, or XMLSpy. But the destination application crashes because of them. I tried to save the file using the overloads of the save method, but the results are worse. Any hint? Is there a way to create a clean xml file? Thanks a lot, Laura Laura Villa wrote:
> Everything seems ok but, if I try to open the file with a byte editor, I That is a BOM (byte order mark). If you don't want that for UTF-8 you > noticed that there are some dirty chars at the beginning of the file: > > <?xml version="1.0" encoding="UTF-8"?> > ... can use new UTF8Encoding(false) to create the encoding and save using that e.g. xmlDocumentInstance.Save(new StreamWriter(File.Open("file.xml", FileMode.Create), new UTF8Encoding(false))); |
|||||||||||||||||||||||