Advertisement
Pctech37

Get Temp 0.1

Nov 19th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Xml;
  3. using System.Net;
  4. using System.IO;
  5.  
  6. // GetTemp 0.1
  7. // Copyright (c) 2011 by Andrew Mock. All rights reserved.
  8. // Special thanks to: marc_s on Stack Overflow
  9. //
  10. // Description: Returns the current temp (F). You'll need a WeatherBug API key,
  11. // and a WeatherBug Station ID.
  12. //
  13. // Syntax: GetTemp.exe APIKey stationID
  14. //
  15. //  calling it like this: GetTenp.exe A0000000000 STATN
  16. //  returns like this: 99.9
  17.  
  18. namespace GetTemp
  19. {
  20.     class Program
  21.     {
  22.         static void Main(string[] args)
  23.         {
  24.             // new 'XML Document' object
  25.             XmlDocument doc = new XmlDocument();
  26.  
  27.             // put the live weather "page" in the "blank" XML Document
  28.             doc.Load("http://www.andrewmock.com/uploads/9/1/0/7/9107466/example.xml");
  29.  
  30.             // new 'XML Namespace Manager' object per our doc's NameTable
  31.             XmlNamespaceManager xmlnsm = new XmlNamespaceManager(doc.NameTable);
  32.  
  33.             // add the "aws" XML Namespace (prefix) to the 'XML Namespace Manager'
  34.             xmlnsm.AddNamespace("aws", "http://www.aws.com/aws");
  35.  
  36.             // create the 'XML Node' object called weather for <aws:weather>
  37.             XmlNode weather = doc.SelectSingleNode("aws:weather", xmlnsm);
  38.  
  39.             // create the 'XML Node' object called weather for <aws:temp>
  40.             XmlNode temp = weather.SelectSingleNode("aws:temp", xmlnsm);
  41.  
  42.             // write the temp in console
  43.             Console.WriteLine(temp.InnerText);
  44.  
  45.             //Console.ReadKey(false);
  46.         }
  47.     }
  48. }
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement