我尝试使用以下代码获取 xml 文件:
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
string xml = string.Empty;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
xml = sr.ReadToEnd();
}
XmlDocument xmlDoc = new XmlDocument();
//xml = xml.Replace((char)(0x1F), ' ');
xmlDoc.LoadXml(xml);
但我得到如下异常:
' ', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.
因此,根据stackoverflow上的许多类似问题,我尝试添加此注释行,但随后出现异常:
Data at the root level is invalid. Line 1, position 2.
怎么了?