I am working with the Yahoo geocoding service, a RESTful XML-based service. I cannot get the XML response fully deserialized.
I've created two classes for the result: PlaceFinderResultSet and Result. PlaceFinderResultSet correctly deserializes the simple types, but I cannot get the complext "Result" node to be deserialized - my Result property is null.
[XmlRoot(ElementName="ResultSet")]
public class PlaceFinderResultSet
{
[XmlElement("Error")]
public int Error { get; set; }
[XmlElement("ErrorMessage")]
public string ErrorMessage { get; set; }
[XmlElement("Locale")]
public string Locale { get; set; }
[XmlElement("Quality")]
public int Quality { get; set; }
[XmlElement("Found")]
public bool Found {get;set;}
[XmlElement("Result",Type=typeof(Result),DataType="Result")]
Result Result { get; set; }
}
[XmlRoot(ElementName = "")]
[XmlType(Namespace = "http://www.tempuri.com", TypeName = "Result")]
public class Result
{
[XmlElement("quality")]
public int Quality{get;set;}
[XmlElement("latitude")]
public double Latitude{get;set;}
/** the rest of the code was omitted for brevity **/
}
Here is an example of the XML I am trying to deserialize:
<?xml version="1.0" encoding="UTF-8"?>
<ResultSet version="1.0">
<Error>0</Error>
<ErrorMessage>No error</ErrorMessage>
<Locale>us_US</Locale>
<Quality>99</Quality>
<Found>1</Found>
<Result>
<quality>72</quality>
<latitude>50.000000</latitude>
<longitude>-77.000000</longitude>
<offsetlat>50.000000</offsetlat>
<offsetlon>-77.000000</offsetlon>
<radius>500</radius>
<name>50 -77</name>
<line1>Route de la Baie-James</line1>
<line2>Baie-James, QC J0Y</line2>
<line3></line3>
<line4>Canada</line4>
<house></house>
<street>Route de la Baie-James</street>
<xstreet></xstreet>
<unittype></unittype>
<unit></unit>
<postal>J0Y</postal>
<neighborhood></neighborhood>
<city>Baie-James</city>
<county>Baie-James</county>
<state>Quebec</state>
<country>Canada</country>
<countrycode>CA</countrycode>
<statecode>QC</statecode>
<countycode></countycode>
<hash></hash>
<woeid>12697261</woeid>
<woetype>11</woetype>
<uzip>J0Y</uzip>
</Result>
</ResultSet>
<!-- gws26.maps.sp1.yahoo.com uncompressed/chunked Sun Jan 2 12:54:55 PST 2011 -->
Ok I had a go, and I got it working by...
Commenting out the [XmlType]
Attribute completely, and.... change this line:
Result Result { get; set; }
to this:
public Result Result { get; set; }
Gah that serializer is picky!