Root element is missing

前端 未结 6 2003
离开以前
离开以前 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:00

    I had the same problem when i have trying to read xml that was extracted from archive to memory stream.

     MemoryStream SubSetupStream = new MemoryStream();
            using (ZipFile archive = ZipFile.Read(zipPath))
            {
                archive.Password = "SomePass";
                foreach  (ZipEntry file in archive)
                {
                    file.Extract(SubSetupStream);
                }
            }
    

    Problem was in these lines:

    XmlDocument doc = new XmlDocument();
        doc.Load(SubSetupStream);
    

    And solution is (Thanks to @Phil):

            if (SubSetupStream.Position>0)
            {
                SubSetupStream.Position = 0;
            }
    

提交回复
热议问题