Root element is missing

前端 未结 6 1997
离开以前
离开以前 2020-12-06 05:52

I am reading xml from xxx URl but i am getting error as Root element is missing.

My code to read xml response is as follows:

  XmlDocument doc = new          


        
6条回答
  •  死守一世寂寞
    2020-12-06 06:22

    Just in case anybody else lands here from Google, I was bitten by this error message when using XDocument.Load(Stream) method.

    XDocument xDoc = XDocument.Load(xmlStream);  
    

    Make sure the stream position is set to 0 (zero) before you try and load the Stream, its an easy mistake I always overlook!

    if (xmlStream.Position > 0)
    {
        xmlStream.Position = 0;
    }
    XDocument xDoc = XDocument.Load(xmlStream); 
    

提交回复
热议问题