Question

What class should I build to help me deserialize this xml in windows phone 7.1?

the xml is this:

<GeocodeResponse>
<status>OK</status>
<result>
<type>route</type>
<formatted_address>Bear Creek Parkway, Redmond, WA 98052, USA</formatted_address>
<address_component>
<long_name>Bear Creek Parkway</long_name>
<short_name>Bear Creek Pkwy</short_name>
<type>route</type>
</address_component>
<address_component>
<long_name>Downtown</long_name>
<short_name>Downtown</short_name>
<type>neighborhood</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Redmond</long_name>
<short_name>Redmond</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>King County</long_name>
<short_name>King County</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Washington</long_name>
<short_name>WA</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United States</long_name>
<short_name>US</short_name>
<type>country</type>
<type>political</type>
</address_component>
<address_component>
<long_name>98052</long_name>
<short_name>98052</short_name>
<type>postal_code</type>
</address_component>
<geometry>
<location>
<lat>47.6695537</lat>
<lng>-122.1241124</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>47.6682316</lat>
<lng>-122.1253234</lng>
</southwest>
<northeast>
<lat>47.6709296</lat>
<lng>-122.1226255</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>47.6690577</lat>
<lng>-122.1241803</lng>
</southwest>
<northeast>
<lat>47.6701035</lat>
<lng>-122.1237686</lng>
</northeast>
</bounds>
</geometry>
</result>
</GeocodeResponse>

I need to deserialize this xml to get the long names and short names, please help me guys:( I have no clue.

Était-ce utile?

La solution

XSD tool can be used to turn XML documents into POCOs.

For raw XML, this is a two step process. The command should be run from the Visual Studio Command prompt - for convenience

1. xsd c:\test.xml  /outputdir:folderPath  (this generates test.xsd)
2. xsd test.xsd /classes  /outputdir:folderPath   (this generates the test.cs) 

Autres conseils

You can deserialize it to a dynamic variable using the XmlSerializer.Deserialize method. Once it's deserialized to the dynamic variable you can just reference it via:

myDynamicVar.long_name
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top