I need to extract XML data from the National Weather Service’s Web Service. It returns XML data as a text string. I’m looking for the best way to get values of elements and attributes from specific nodes. The code below throws this error on the last line:
System.InvalidOperationException: <dwml xmlns=''> was not expected.
// Get weather forecast string strWxXml = ""; gov.weather.graphical.weatherParametersType paramsWX = new detailwindow.gov.weather.graphical.weatherParametersType(); paramsWX.wx = true; gov.weather.graphical.ndfdXML xmlWx = new detailwindow.gov.weather.graphical.ndfdXML(); DateTime dtStart = DateTime.Now; DateTime dtEnd = DateTime.Now.AddDays(5.00); Decimal longitude = 39.73M; Decimal latitude = -86.27M; // Call web service proxy class strWxXml = xmlWx.NDFDgen(longitude, latitude, 0, dtStart, dtEnd, 0, paramsWX); DataSet dsXML = new DataSet(); System.IO.StringReader read = new StringReader(strWxXml); System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(dsXML.GetType()); System.Xml.XmlReader reader = new XmlTextReader(read); dsXML = (DataSet)serializer.Deserialize(reader);
I have also tried adding this above the partial class statement:
[Serializable, System.Xml.Serialization.XmlRoot("dwml")]