Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Xml;
  10. using System.Net;
  11.  
  12. namespace Weather_App
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. //getData();
  20. extractCurrent();
  21. }
  22.  
  23. private void getData()
  24. {
  25. WebClient Client = new WebClient();
  26.  
  27. //current weather
  28. Client.DownloadFile(@"http://api.openweathermap.org/data/2.5/weather?q=Stratford&mode=xml&units=metric", "weatherData.xml");
  29. Client.DownloadFile(@"http://api.openweathermap.org/data/2.5/forecast?q=Stratford,CA&mode=xml&units=metric&cnt=7", "weatherData7Day.xml");
  30.  
  31. }
  32.  
  33. private void extractCurrent()
  34. {
  35. //load xml data
  36. XmlDocument doc = new XmlDocument();
  37. doc.Load("weatherData.xml");
  38.  
  39. XmlNode parent;
  40. parent = doc.DocumentElement;
  41.  
  42. //get the city name and show it to screen
  43. foreach (XmlNode child in parent.ChildNodes)
  44. {
  45. if (child.Name == "city")
  46. {
  47. cityOutput.Text = child.Attributes["name"].Value;
  48. }
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement