w.WriteEndDocument();

w.Flush();
w.Close();

string xml = Encoding.UTF8.GetString(stream.ToArray());

XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xml);

经过仔细调试发现问题出现在. UTF8或者Unicode编码转换时,第一个字符转换会出现一个?号。
所以,为避免异常。还应加上。

xml = xml.Substring(1, xml.Length - 1);

然后再 LoadXml(xml) 就不会出错了。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
猜你喜欢
  • 2022-01-14
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案