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);
}
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM