1. 程式人生 > 其它 >C#取XML<string></string>值

C#取XML<string></string>值

例如:

<ArrayOfStringxmlns:xsi="#"xmlns:xsd="#"xmlns="#"> <string>1</string> <string>2</string> <string>3</string> </ArrayOfString>
 public async Task<WeatherContext> Weather(string city)
        {
            var client = new RestClient(_config["Weatherurl
"]+ city); client.Timeout = -1; var request = new RestRequest(Method.GET); IRestResponse response = client.Execute(request); string[] s = new string[3];//宣告string陣列存放返回結果 string bl = ""; string z = response.Content;
int k = 0; bool b = true; for (int i = 0; i < z.Length-8; i++) { if (b) { bl = z.Substring(i, 8); } if (bl.Equals("<string>")) { if (z.Substring(i+8
,1)!="<") { b = false; s[k] += z.Substring(i + 8, 1); } else { b = true; k++; i += 8; } } } WeatherContext weather = new WeatherContext { 1 = s[0], 2 = s[1], 3 = s[2], }; return weather; }