Reputation: 430
Im trying to deserialize this xml response of wcf web service to List using XmlSerializer but it fails with exception message :There is an error in XML document (1, 2)
xml:
<ArrayOfNote xmlns="http://schemas.datacontract.org/2004/07/NotebookService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Note>
<Author>Redouane</Author>
<Body>Test note</Body>
<CreationDate>2014-01-28T00:00:00</CreationDate>
<Id>1</Id>
<Title>Hello World</Title>
</Note>
</ArrayOfNote>
c#:
public class Note
{
public int Id { get; set; }
public string Title { get; set; }
public System.DateTime CreationDate { get; set; }
public string Author { get; set; }
public string Body { get; set; }
}
and this is the code i wrote to deserialize the received stream
private HttpClient client = new HttpClient();
private List<Note> notes = new List<Note>();
. . .
XmlSerializer serializer = new XmlSerializer(typeof(List<Note>));
var responseData = await response.Content.ReadAsStreamAsync();
List<Note> list = serializer.Deserialize(responseData) as List<Note>;
Please help!
Upvotes: 2
Views: 475
Reputation: 116118
Change the creation of serializer as follows and it should work.
XmlSerializer serializer = new XmlSerializer(typeof(List<Note>),
new XmlRootAttribute("ArrayOfNote") {
Namespace = "http://schemas.datacontract.org/2004/07/NotebookService"
});
Upvotes: 2