2014-01-29 74 views
0

我只是XML和ASP.NET的开端。我的要求是使用从第三方服务收到的xml响应绑定下拉列表geonames.org。作为一个例子,我想绑定我的下拉列表中的国家名称从该XML响应。所以我怎么能做到这一点。使用http xml响应绑定下拉列表

这是从geonames.org

http://api.geonames.org/countryInfo?username=[myusername]

和下面的响应XML

<geonames> 
<country> 
<countryCode>AD</countryCode> 
<countryName>Andorra</countryName> 
<isoNumeric>020</isoNumeric> 
<isoAlpha3>AND</isoAlpha3> 
<fipsCode>AN</fipsCode> 
<continent>EU</continent> 
<continentName>Europe</continentName> 
<capital>Andorra la Vella</capital> 
<areaInSqKm>468.0</areaInSqKm> 
<population>84000</population> 
<currencyCode>EUR</currencyCode> 
<languages>ca</languages> 
<geonameId>3041565</geonameId> 
<west>1.4071867141112762</west> 
<north>42.65604389629997</north> 
<east>1.7865427778319827</east> 
<south>42.42849259876837</south> 
</country> 
<country> 
<countryCode>AE</countryCode> 
<countryName>United Arab Emirates</countryName> 
<isoNumeric>784</isoNumeric> 
<isoAlpha3>ARE</isoAlpha3> 
<fipsCode>AE</fipsCode> 
<continent>AS</continent> 
<continentName>Asia</continentName> 
<capital>Abu Dhabi</capital> 
<areaInSqKm>82880.0</areaInSqKm> 
<population>4975593</population> 
<currencyCode>AED</currencyCode> 
<languages>ar-AE,fa,en,hi,ur</languages> 
<geonameId>290557</geonameId> 
<west>51.58332824707031</west> 
<north>26.08415985107422</north> 
<east>56.38166046142578</east> 
<south>22.633329391479492</south> 
</country> 
--------------- 
--------------- 
etc..... 

所以一个例子从上面的URL,这将返回在这种结构中的XML ..那么如何使用它来绑定我的下拉菜单。

回答

0

ASP.NET提供了用于访问XML中标记的数据的XmlDataSource控件。

然后,您可以绑定像这样:

ddlStatus.DataSource = iObjDropDownRetrieval.GetXMLDataSource("~/XMLDatasource/FacilityStatus.xml"); 
ddlStatus.DataTextField = "Name"; 
ddlStatus.DataValueField = "Value"; 
ddlStatus.DataBind(); 
+0

对不起,我在这方面的知识较少。我的问题是,如何使用该thrirdparty URL中的XML响应来实现此目的。这意味着从http://api.geonames.org/countryInfo?username=[myusername] –