I'm attempting to deserialize an XML response from an API. The data is as follows (I have only included a small chunk for the sake of a small post):
<ns1:alerts xmlns:ns1="http://gov.fema.ipaws.services/feed">
<alert xmlns="urn:oasis:names:tc:emergency:cap:1.2">
<identifier>All-Channels-Test-Message-RT_Automation_124_789f95e3-e02f-4e61-8121
My code to deserialize this data is as follows:
var serializer = new XmlSerializer(
typeof(List<Alert>),
new XmlRootAttribute("alerts") { Namespace = "http://gov.fema.ipaws.services/feed" });
var alerts = serializer.Deserialize(stream) as Alert[];
In my Alert class, I have attributes set with the namespace and root element for the alert:
[XmlRoot("alert", Namespace = "urn:oasis:names:tc:emergency:cap:1.2")]
public class Alert
When I go to deserialize a list of alert instances, I get a result of 0 instance. I have verified that the response is formatted correctly. There are 1-2 depending on the dummy alerts on the API feed. My guess is I am deserializing incorrectly. How can I deserialize this properly?