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;
- // GetTemp 0.1
- // Copyright (c) 2011 by Andrew Mock. All rights reserved.
- // Special thanks to: marc_s on Stack Overflow
- //
- // Description: Returns the current temp (F). You'll need a WeatherBug API key,
- // and a WeatherBug Station ID.
- //
- // Syntax: GetTemp.exe APIKey stationID
- //
- // calling it like this: GetTenp.exe A0000000000 STATN
- // returns like this: 99.9
- namespace GetTemp
- {
- class Program
- {
- static void Main(string[] args)
- {
- // new 'XML Document' object
- XmlDocument doc = new XmlDocument();
- // put the live weather "page" in the "blank" XML Document
- doc.Load("http://www.andrewmock.com/uploads/9/1/0/7/9107466/example.xml");
- // new 'XML Namespace Manager' object per our doc's NameTable
- XmlNamespaceManager xmlnsm = new XmlNamespaceManager(doc.NameTable);
- // add the "aws" XML Namespace (prefix) to the 'XML Namespace Manager'
- xmlnsm.AddNamespace("aws", "http://www.aws.com/aws");
- // create the 'XML Node' object called weather for <aws:weather>
- XmlNode weather = doc.SelectSingleNode("aws:weather", xmlnsm);
- // create the 'XML Node' object called weather for <aws:temp>
- XmlNode temp = weather.SelectSingleNode("aws:temp", xmlnsm);
- // write the temp in console
- Console.WriteLine(temp.InnerText);
- //Console.ReadKey(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement