<SERVERS> <SERVER name="1"> <url>http://someeather.com/database.xml</url> <search>xml/searchpath/here</search> </SERVER> <SERVER name="2"> <url>http://otherweather.com/database.xml</url> <search>xml/searchpath/here</search> </SERVER> <SERVER name="3"> <url>http://anotherweather.com/database.xml</url> <search>xml/searchpath/here</search> </SERVER> </SERVERS>
XmlNodeList urls = serverDoc.SelectNodes("//servers/server"); string id1 = "1; string id2 = "2"; string id3 = "3"; foreach(XmlNode node in urls) { string server1 = node.Attributes["name"].InnerText; //Get the attribute name //Check if attribute value matches the 'id' provided before foreach. if (server1 == name1) { //Create new node list, so we can get the server url. XmlNodeList urls2 = serverDoc.SelectNodes("//servers/server"); foreach (XmlNode node2 in urls2) { var serverPath = temp.InnerText; //Get the serverpath (the <search> node in .xml) WebRequest request = WebRequest.Create(node2["url"].InnerText); //Get the nodes with the name <url>. var response = request.GetResponse(); //Get a response from the server, based on the request node url, that matched the 'name' attribute with the 'id' before this code. Stream stream = response.GetResponseStream(); //Create new stream from the external server for reading XmlDocument responseDoc = new XmlDocument(); //Create new instance for a new xml document responseDoc.Load(stream); //Create new xml document from the stream var tempOut = responseDoc.SelectSingleNode(serverPath); //From this new document get the temperature based on the searchpath provided befre this code. string temperature = tempOut.Attributes["value"].Value; //Now get the value from the attribute with the name 'value' from that new xml document, to set the temperature. SetTemperature1(temperature); //Set the value on our method which sets this value on the templbl on our mainview. } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)