C#读取XML文件中有乱码的处理办法
1.以文本的方式读取出xml内容
2.如果xml加载文本失败,替换掉乱码的内容
private static void loadxml(XmlDocument doc, string str) { try { doc.LoadXml(str); } catch (System.Xml.XmlException ex) { long count = 1; int position = 0; while (count < ex.LineNumber && (position = str.IndexOf('\n', position)) != -1) { count++; position++; } string Newstr=str.Replace(str.Substring(position + ex.LinePosition - 1, 1), ""); loadxml(doc, Newstr); } }
慎于行,敏于思!GGGGGG