Advertisement
Pctech37

Get Temp

Nov 19th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Xml;
  3. using System.Net;
  4. using System.IO;
  5.  
  6. namespace GetTemp
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             XmlDocument doc = new XmlDocument();
  13.             doc.LoadXml(downloadWebPage("http://www.andrewmock.com/uploads/9/1/0/7/9107466/example.xml"));
  14.  
  15.             XmlNamespaceManager man = new XmlNamespaceManager(doc.NameTable);
  16.             man.AddNamespace("aws", "www.aws.com/aws");
  17.  
  18.             XmlNode weather = doc.SelectSingleNode("aws:weather", man);
  19.             Console.WriteLine(weather.InnerText);
  20.             Console.ReadKey(false);
  21.         }
  22.  
  23.         private static string downloadWebPage(string url)
  24.         {
  25.             // open a connection
  26.             HttpWebRequest wReqObj = (HttpWebRequest)HttpWebRequest.Create(url);
  27.  
  28.             // request response
  29.             WebResponse wResp = wReqObj.GetResponse();
  30.  
  31.             // open data stream
  32.             Stream wStream = wResp.GetResponseStream();
  33.  
  34.             // Create reader object:
  35.             StreamReader sReader = new StreamReader(wStream);
  36.  
  37.             // read the entire stream content
  38.             string pageContent = sReader.ReadToEnd();
  39.  
  40.             // cleanup
  41.             sReader.Close();
  42.             wStream.Close();
  43.             wResp.Close();
  44.  
  45.             // return the actual web page as string
  46.             return pageContent;
  47.         }
  48.     }
  49. }
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement