Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Xml;
- using System.Net;
- using System.IO;
- namespace GetTemp
- {
- class Program
- {
- static void Main(string[] args)
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(downloadWebPage("http://www.andrewmock.com/uploads/9/1/0/7/9107466/example.xml"));
- XmlNamespaceManager man = new XmlNamespaceManager(doc.NameTable);
- man.AddNamespace("aws", "www.aws.com/aws");
- XmlNode weather = doc.SelectSingleNode("aws:weather", man);
- Console.WriteLine(weather.InnerText);
- Console.ReadKey(false);
- }
- private static string downloadWebPage(string url)
- {
- // open a connection
- HttpWebRequest wReqObj = (HttpWebRequest)HttpWebRequest.Create(url);
- // request response
- WebResponse wResp = wReqObj.GetResponse();
- // open data stream
- Stream wStream = wResp.GetResponseStream();
- // Create reader object:
- StreamReader sReader = new StreamReader(wStream);
- // read the entire stream content
- string pageContent = sReader.ReadToEnd();
- // cleanup
- sReader.Close();
- wStream.Close();
- wResp.Close();
- // return the actual web page as string
- return pageContent;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement