Chelsea_cole
Chelsea_cole

Reputation: 1095

Convert xml file encoding UTF-8 to ANSI

I have a WordPress xml data file encoding with utf-8. But the WordPress impoter recognizes "Invalid file - Please upload a valid WXR (WordPress eXtended RSS) export file". So, i copy all text in the xml file and paste into Notepad++, then i save as a new xml file (encoding was: ANSI). But now, i import the new xml file to WordPress and there are no problem!

What's wrong with WordPress RSS encoding UTF-8? And how to convert a xml file encoding UTF-8 to ANSI using C#? Thanks for reading! :)

Upvotes: 2

Views: 4918

Answers (1)

Ishmael
Ishmael

Reputation: 32570

It's unlikely that WordPress is cranky about UTF-8. Maybe it is cranky about a BOM (byte order mark). You can supress the BOM in your XmlWriter thus:

XmlWriterSettings settings = new XmlWriterSettings();
// supress BOM since it confuses many parsers
settings.Encoding = new UTF8Encoding(false);
using (XmlWriter writer = XmlWriter.Create(path, settings)) {
   ...
}

Upvotes: 1

Related Questions