Get nodes from asmx service that return string XML, C# -


i trying query public web service returns following xml:

this xml file not appear have style information associated it. document tree shown below.

<string xmlns="http://www.webservicex.net"> <newdataset> <table> <country>maldives</country> <city>gan</city> </table> <table> <country>maldives</country> <city>male</city> </table> </newdataset> </string> 

how can list of cities in c# loading dropdowlist?

this code:

var restclient = new restclient("http://www.webservicex.net/globalweather.asmx/getcitiesbycountry");         var request = new restrequest(method.get);         // request.resource = "{version}/token";         request.addparameter("countryname", "maldives");           var response = restclient.execute(request); 

//response.content contains troublesome string

i appreciate help, thanks.

looks xml consists of output of dataset.writexml(writer, xmlwritemode.ignoreschema) wrapped in root element named "{http://www.webservicex.net}string". easiest deserialize inner xml dataset bind appropriate column of appropriate datatable:

first, deserialize set:

        var rootelement = xelement.parse(xmlstring); // xmlstring //response.content          var set = new dataset();         var setelement = rootelement.descendantsandself().where(e => e.name.localname == "newdataset").firstordefault();         if (setelement != null)         {             using (var reader = setelement.createreader())             {                 set.readxml(reader, xmlreadmode.auto);             }         } 

next, pick out table column named "city":

        var table = set.tables.cast<datatable>().firstordefault(t => t.columns["city"] != null); 

now have datatable, can bind following instructions in what right way populate dropdownlist database?, dropdownlist datasource and/or databind dropdownlist using datatextfield = "city".


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -