您可以通过将整个 XML 文件读入内存并按照自己的方式来以一种非常狡猾的方式执行此操作:
string content = "";
// Read the XML file into content
StreamReader reader = new StreamReader("file.xml");
content = reader.ReadToEnd();
reader.Close();
// Find the character position just after the <?xml token, and just before the ?> token
int openIndex = content.IndexOf("<?xml", StringComparison.OrdinalIgnoreCase) + 5;
int closeIndex = content.IndexOf("?>", openIndex);
// Get the bits between <?xml and ?>
string header = content.Substring(openIndex, closeIndex - openIndex);
// Substitute version string.
header = header.Replace("version=\"1.1\"", "version=\"1.0\"");
// Put Humpty Dumpty back together again.
content = string.Concat(content.Substring(0, openIndex), header, content.Substring(closeIndex));
// Feed content into an XMLReader (or equivalent) here.
它适用于您提供的示例字符串,但我尚未在格式不完善的 XML 文档上对其进行测试。