Removing XML Deserialization from the Web

In general, this is how I deserialize the XML file:

    string location = "C:\\test.xml";
    XmlObjectClass member_data = new XmlObjectClass();

                using (Stream XmlStream = new FileStream(location,FileMode.Open))
                {
                    data = (XmlObjectClass)serializer.Deserialize(XmlStream);
                }

This works when I deserialize the XML file, but what if I want to deserialize the XML that is returned by the web request (i.e. by going to the URL)?

+3
source share
2 answers

Well, there are several options:

  • Build XmlReaderwith XmlReader.Create(uri)and deserialize directly
  • Get stream from WebClientor HttpWebRequestand deserialize stream
  • Extract all the data, then create a stream around it with MemoryStreamand deserialize from this

- - - "GET" URI, , , .

+8

, MemoryStream, a StringReader , XmlSerializer.Deserialize().

0

Source: https://habr.com/ru/post/1774620/


All Articles