I am able to deserialize a local XML file by passing a textReader object to the xmlSerializer.D eserialize method.
My problem Iis that I need to pass a XML file path in form of a URL instead of a local file. I use a webRequest class to read the file, code as below:
// Create a 'WebRequest' object with the specified url.
WebRequest myWebRequest = WebRequest.Crea te(xmlPath);
// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.Ge tResponse();
// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = myWebResponse.G etResponseStrea m();
System.Text.Enc oding encode = System.Text.Enc oding.GetEncodi ng("utf-8");
// Pipe the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(Re ceiveStream, encode);
XmlSerializer serializer = new XmlSerializer(t ypeof(bookCatal og));
myBookCatalog = (bookCatalog)se rializer.Deseri alize(ReceiveSt ream);
However I am getting an error "There is an error in XML document (0, 0)." on the last line. Does anyone know what the problem could be?
Thanks in advance for any help.
My problem Iis that I need to pass a XML file path in form of a URL instead of a local file. I use a webRequest class to read the file, code as below:
// Create a 'WebRequest' object with the specified url.
WebRequest myWebRequest = WebRequest.Crea te(xmlPath);
// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.Ge tResponse();
// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = myWebResponse.G etResponseStrea m();
System.Text.Enc oding encode = System.Text.Enc oding.GetEncodi ng("utf-8");
// Pipe the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(Re ceiveStream, encode);
XmlSerializer serializer = new XmlSerializer(t ypeof(bookCatal og));
myBookCatalog = (bookCatalog)se rializer.Deseri alize(ReceiveSt ream);
However I am getting an error "There is an error in XML document (0, 0)." on the last line. Does anyone know what the problem could be?
Thanks in advance for any help.
Comment