C# Stream Reader adding \\n to XML

拈花ヽ惹草 提交于 2019-12-08 10:48:28

You need XmlDoc.LoadXml if you're going to load a string. Load loads from a file.


BTW, the alternative is also more efficient. You can load the document directly from the stream:

WebRequest webRequest = WebRequest.Create(Url);
using (WebResponse webResponse = webRequest.GetResponse())
{
    using (Stream responseStream = webResponse.GetResponseStream())
    {
        XmlDocument XmlDoc = new XmlDocument();
        GeoCode oGeoCode = new GeoCode();
        XmlDoc.Load(responseStream);
    }
}

The using statements ensure that the WebResponse and Stream get cleaned up, even if an exception is thrown.

y not just do

   GeoCodeXml=GeoCodeXml.Replace("\n","");

if it is truly returning the \n as mentioned here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!