“Root element is missing” error but I have a root element

前端 未结 3 1070
遇见更好的自我
遇见更好的自我 2021-01-07 17:21

If anyone can explain why I\'m getting a \"Root element is missing\" error when my XML document (image attached) has a root element, they win a pony which fires lazers from

3条回答
  •  不要未来只要你来
    2021-01-07 17:32

    Your problem is due to this line:

    xml = reader.ReadToEnd();
    

    This positions the reader stream to the end so that when XmlReader.Create is executed, there is nothing left in the stream for it to read.

    If you need the xml string to be populated, then you need to close and reopen the reader prior to XmlReader.Create. Otherwise, removing or commenting this line out will solve your problem.

提交回复
热议问题