简体   繁体   中英

loading a responsestream into an XDocument, root element is missing

I have read that setting the position of the stream to 0 resolves this, but this fails as the stream "does not support seek operations".

It fails on this:

XDocument doc = XDocument.Load(resp.GetResponseStream());

Reading the stream:

string t = new StreamReader(resp.GetResponseStream(), Encoding.Default).ReadToEnd();

...reveals that my xml could not be any simpler:

<xml version="1.0">
  <ActiveStorms>
  </ActiveStorms>
</xml>

Is this somehow malformed?

Thanks for any help, Mike

XML documents do not end with a </xml> closing tag so delete that. The initial <xml version="1.0"> should be: <?xml version="1.0"> (note the question mark).

So a valid version would look like:

<?xml version="1.0">
<ActiveStorms>
</ActiveStorms>

The right XML declaration is

<?xml version="1.0" encoding="utf-8" ?>

and after that add your root node <ActiveStorms> so,

<?xml version="1.0" encoding="utf-8" ?>
<ActiveStorms>
</ActiveStorms>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM