I am attempting to read an XML response from a ASP.NET
Web API into a DataSet
so that I can bind it to a DropDownList
. When reading the response however, I am met with Data at the root level is invalid. Line 1, position 1.
Snipp:
WebRequest request = WebRequest.Create("EndPointURL");
request.Method = "GET";
WebResponse response = request.GetResponse();
DataSet ds = new DataSet();
using (StreamReader rdr = new StreamReader(response.GetResponseStream()))
{
ds.ReadXml(rdr); //EXCEPTION Data at the root level is invalid. Line 1, position 1.
}
Sample of XML response:
<ArrayOfPerson xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MySchema">
<Person>
<Address1 xmlns="http://schemas.datacontract.org/2004/07/ClassSchema">123 Main Street</Address1>
<Address2 xmlns="http://schemas.datacontract.org/2004/07/ClassSchema"">None</Address2>
...FOR BREVITY
</Person>
<Person>
..FOR BREVITY
</Person>
.
.
.
</ArrayOfPerson>
I have successfully made this call to other end points of the API so I'm a little stumped. I do not see anything at Line 1, position 1
that looks like an invalid XML character. What could possibly be throwing the error?