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
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.