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