The following code breaks when the XML has data like "Lord & Hogan". Any suggestions? Thanks, Ken
private T GetResponse<T>(String apiObject, String query)
{
//Deserialize XML into the type specified.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(BuildRequestUri(apiObject, query));
using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
{
try
{
XmlSerializer ser = new XmlSerializer(typeof(T));
return (T)ser.Deserialize(resp.GetResponseStream());
}
catch (Exception e)
{
error = e.InnerException.ToString();
return default(T);
}
}
}
From here:
A literal ampersand inside an XML tag is not allowed by the XML standard, and such a document will fail to parse by any XML parser.
Other similar questions on StackOverflow:
you should XML-encode data like "Lord & Hogan". It should be encoded like this:
"Lord & Hogan"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With