I"m new to APIs and using C# with XML and all of that..
I registered and received the ID and Key from Weather.com. I have the URL that i want to go to... The URL of course is XML... I have an understanding of adding and using web references... but this is different... how do i go to this url, then get the information
(XML) and display it on my webpage? Any good reading out there? or anyone who has come across this API? Or just any help in General? Here's the URL
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Xml;
using System.IO;
public partial class Weather : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String reqUrl = "http://xoap.weather.com/weather/local/29206?cc=*&dayf=" +
ConfigurationSettings.AppSettings.Get("ExtForecastLength") +
"&prod=xoap&par=" + ConfigurationSettings.AppSettings.Get("PartnerID") +
"&key=" + ConfigurationSettings.AppSettings.Get("LicenseKey");
// First we request our content from our provider source .. in this case .. The Weather Channel
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(reqUrl);
//load the response into a response object
WebResponse resp = wr.GetResponse();
// create a new stream that can be placed into an XmlTextReader
Stream str = resp.GetResponseStream();
XmlTextReader reader = new XmlTextReader(str);
reader.XmlResolver = null;
// create a new Xml document
XmlDocument doc = new XmlDocument();
doc.Load(reader);
// set out object properties
Xml1.Document = doc;
Xml1.TransformSource = "XSLTFile.xslt";
Awesome, Thanks surajitkhamrai. How can i get pieces of this on a web form... for instance the <xsl:value-of select"cc/tmp" /> is actual temperature... how could i get that on the bottom of my web page or top... would i have to create a new<asp:Xml.....
tag every time?
Member
28 Points
116 Posts
xoap Weather Channel API
Sep 22, 2009 05:56 PM|bedubs|LINK
I"m new to APIs and using C# with XML and all of that..
I registered and received the ID and Key from Weather.com. I have the URL that i want to go to... The URL of course is XML... I have an understanding of adding and using web references... but this is different... how do i go to this url, then get the information (XML) and display it on my webpage? Any good reading out there? or anyone who has come across this API? Or just any help in General? Here's the URL
http://xoap.weather.com/weather/local/30339?cc=*&dayf=5&link=xoap&prod=xoap&par=1139641129&key=3de195081565d649
Member
160 Points
83 Posts
Re: xoap Weather Channel API
Sep 23, 2009 05:05 AM|surajitkhamrai|LINK
ref:http://www.odetocode.com/Articles/125.aspx
in web.config
<appSettings>
<add key="PartnerID" value="1139641129"/>
<add key="LicenseKey" value="3de195081565d649" />
<add key="ExtForecastLength" value="5" />
</appSettings>
weather.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Weather.aspx.cs" Inherits="Weather" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Xml ID="Xml1" runat="server"></asp:Xml>
</div>
</form>
</body>
</html>
Weather.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Xml;
using System.IO;
public partial class Weather : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String reqUrl = "http://xoap.weather.com/weather/local/29206?cc=*&dayf=" +
ConfigurationSettings.AppSettings.Get("ExtForecastLength") +
"&prod=xoap&par=" + ConfigurationSettings.AppSettings.Get("PartnerID") +
"&key=" + ConfigurationSettings.AppSettings.Get("LicenseKey");
// First we request our content from our provider source .. in this case .. The Weather Channel
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(reqUrl);
//load the response into a response object
WebResponse resp = wr.GetResponse();
// create a new stream that can be placed into an XmlTextReader
Stream str = resp.GetResponseStream();
XmlTextReader reader = new XmlTextReader(str);
reader.XmlResolver = null;
// create a new Xml document
XmlDocument doc = new XmlDocument();
doc.Load(reader);
// set out object properties
Xml1.Document = doc;
Xml1.TransformSource = "XSLTFile.xslt";
}
}
XSLTFile.xslt:-
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/weather">
<table width="225px" border="0" cellSpacing="0" cellPadding="0" bgcolor="EFF5D7" ID="Table1">
<tr>
<td colspan="2" align="center" valign="center"
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana">
<xsl:value-of select="loc/dnam"></xsl:value-of>
</td>
</tr>
<tr>
<xsl:variable name="med-img-dir">./images/weather/64x64</xsl:variable>
<xsl:variable name="img-ext">png</xsl:variable>
<xsl:variable name="iconnumber">
<xsl:value-of select="cc/icon"></xsl:value-of>
</xsl:variable>
<td height="64px" width="64px" align="center" valign="center">
<img src="{$med-img-dir}/{$iconnumber}.{$img-ext}"></img>
</td>
<td width="161px" align="center" valign="center" style="FONT-SIZE: 22pt;
FONT-WEIGHT: bold">
<xsl:value-of select="cc/tmp"></xsl:value-of>°F
</td>
</tr>
<tr>
<td align="center" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana; HEIGHT: 33px">
<xsl:value-of select="cc/t"></xsl:value-of>
</td>
<td align="center" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana; HEIGHT: 33px">
Feels like
<xsl:value-of select="cc/flik"></xsl:value-of>°F
</td>
</tr>
<table width="225px" border="0" cellSpacing="0" cellPadding="0" bgcolor="EFF5D7" ID="Table2">
<tr>
<td width="10%"></td>
<td width="50%" align="left" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
UV Index:
</td>
<td width="40%" align="left" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
<xsl:value-of select="cc/uv/i"></xsl:value-of>
<xsl:value-of select="cc/uv/t"></xsl:value-of>
</td>
</tr>
<tr>
<td width="10%"></td>
<td width="50%" align="left" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
Dew Point:
</td>
<td width="40%" align="left" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
<xsl:value-of select="cc/dewp"></xsl:value-of>°F
</td>
</tr>
<tr>
<td width="10%"></td>
<td width="50%" align="left" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
Humidity:
</td>
<td width="40%" align="left" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
<xsl:value-of select="cc/hmid"></xsl:value-of>%
</td>
</tr>
<tr>
<td width="10%"></td>
<td width="50%" align="left" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
Visibility:
</td>
<td width="40%" align="left" valign="center" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
<xsl:value-of select="cc/vis"></xsl:value-of>miles
</td>
</tr>
<tr>
<td width="10%"></td>
<td width="50%" align="left" valign="top" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
Pressure:
</td>
<td width="40%" align="left" valign="top" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
<xsl:value-of select="cc/bar/r"></xsl:value-of>inches and
<xsl:value-of select="cc/bar/d"></xsl:value-of>
</td>
</tr>
<tr>
<td width="10%"></td>
<td width="50%" align="left" valign="top" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
Wind:
</td>
<td width="40%" align="left" valign="top" style="FONT-SIZE: 9pt; COLOR: black;
FONT-FAMILY: Verdana">
<xsl:value-of select="cc/wind/s"></xsl:value-of>mph
</td>
</tr>
</table>
<table width="225px" border="0" cellSpacing="0" cellPadding="0" bgcolor="EFF5D7" ID="Table3">
<tr>
<td colspan="5" width="100%" align="center"><u>Extended Forecast</u></td>
</tr>
<tr>
<xsl:for-each select="dayf/day">
<xsl:if test="@d > 0">
<td width="25%" align="center" valign="top" style="FONT-SIZE: 7pt; COLOR: black;
FONT-FAMILY: Verdana">
<xsl:value-of select="@t"></xsl:value-of>
</td>
</xsl:if>
</xsl:for-each>
</tr>
<tr>
<xsl:variable name="small-img-dir">./images/weather/32x32</xsl:variable>
<xsl:variable name="img-ext">png</xsl:variable>
<xsl:for-each select="dayf/day">
<xsl:if test="@d > 0">
<xsl:variable name="iconnumber">
<xsl:value-of select="part/icon"></xsl:value-of>
</xsl:variable>
<td width="25%" align="center" valign="center">
<img border="1" src="{$small-img-dir}/{$iconnumber}.{$img-ext}"></img>
</td>
</xsl:if>
</xsl:for-each>
</tr>
<tr>
<xsl:for-each select="dayf/day">
<xsl:if test="@d > 0">
<td width="25%" align="center" valign="top" style="FONT-SIZE: 7pt; COLOR: black;
FONT-FAMILY: Verdana">
High:
<xsl:value-of select="hi"></xsl:value-of>
</td>
</xsl:if>
</xsl:for-each>
</tr>
<tr>
<xsl:for-each select="dayf/day">
<xsl:if test="@d > 0">
<td width="25%" align="center" valign="top" style="FONT-SIZE: 7pt; COLOR: black;
FONT-FAMILY: Verdana">
Low:
<xsl:value-of select="low"></xsl:value-of>
</td>
</xsl:if>
</xsl:for-each>
</tr>
<tr>
<xsl:for-each select="dayf/day">
<xsl:if test="@d > 0">
<td width="25%" align="center" valign="top" style="FONT-SIZE: 7pt; COLOR: black;
FONT-FAMILY: Verdana">
<xsl:value-of select="part/t"></xsl:value-of>
</td>
</xsl:if>
</xsl:for-each>
</tr>
</table>
<table width="225px" border="0" cellSpacing="0" cellPadding="4" bgcolor="EFF5D7" ID="Table4">
<tr>
<xsl:variable name="twclink">http://www.weather.com/?prod=xoap</xsl:variable>
<td width="20%" align="center" valign="top" style="FONT-SIZE: 7pt; COLOR: black;
FONT-FAMILY: Verdana">
Weather data provided by<a href="{$twclink}" target="_none">
<img border="0" src="./images/weather/logos/TWClogo_32px.png"></img></a>
</td>
</tr>
</table>
</table>
</xsl:template>
</xsl:stylesheet>
hope this will help you
Member
28 Points
116 Posts
Re: xoap Weather Channel API
Sep 23, 2009 09:17 AM|bedubs|LINK
Awesome, Thanks surajitkhamrai. How can i get pieces of this on a web form... for instance the <xsl:value-of select"cc/tmp" /> is actual temperature... how could i get that on the bottom of my web page or top... would i have to create a new<asp:Xml..... tag every time?
Member
160 Points
83 Posts
Re: xoap Weather Channel API
Sep 24, 2009 09:10 AM|surajitkhamrai|LINK
yes,i think you need anothe xml and xslt for that
None
0 Points
1 Post
Re: xoap Weather Channel API
May 05, 2011 09:08 AM|Maksymilian Mulawa|LINK
You could use http://weatherclient.codeplex.com/, which wraps most of the Weather.com API.