Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml;
- using System.Net;
- namespace Weather_App
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- //getData();
- extractCurrent();
- }
- private void getData()
- {
- WebClient Client = new WebClient();
- //current weather
- Client.DownloadFile(@"http://api.openweathermap.org/data/2.5/weather?q=Stratford&mode=xml&units=metric", "weatherData.xml");
- Client.DownloadFile(@"http://api.openweathermap.org/data/2.5/forecast?q=Stratford,CA&mode=xml&units=metric&cnt=7", "weatherData7Day.xml");
- }
- private void extractCurrent()
- {
- //load xml data
- XmlDocument doc = new XmlDocument();
- doc.Load("weatherData.xml");
- XmlNode parent;
- parent = doc.DocumentElement;
- //get the city name and show it to screen
- foreach (XmlNode child in parent.ChildNodes)
- {
- if (child.Name == "city")
- {
- cityOutput.Text = child.Attributes["name"].Value;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement