c# - Why would XElement.Load accept a Stream? -


Why does XElement.Load accept a stream?

I stuck on this for a while because I was parsing a stream from an HTTP Web Response stream and I thought it would convert bytes to string. However, this was not the case and I would be able to read the method properly to use the string reader to stream the stream into something.

My original code that compiles, but fails at runtime:

  stream datastream = response. Gateresonsstream (); Var xmlResult = XElement.Load (datastream);  

will issue an error above that says "the root element is missing". It can be passed by using a string commander and instead.

Is there any such case where a stream will be used for this method?

Maybe there is an encoding problem. You can not close the bytes of XML. You can only parse it by characters. The byte of the stream should be changed to the first letter.

It seems that there is no basic element after decoding the characters or there is garbage before the original element.

Now what XElement.Load looks by default appears to be the encoding ( XmlTextReaderImpl.DetectEncoding ). Find out what's in your encoding of data and layers between StreamReader to stream and XML framework. Set the right encoding.


Comments