Yahoo Weather Feed

S

StewartS

Hi there, I'm looking to display the Yahoo Weather feed on my website
(http://developer.yahoo.com/weather/). I am using Visual Web Developer
2005.

Everything works fine while parsing normal lines in the feed like this
(on the aspx page):

<asp:DataList ID="DataList1" runat="server"
DataSourceID="XmlDataSourceEd" Width="523px">
<ItemTemplate>
<%#XPath("title")%><br />
<%#XPath("description")%><br />
<%#XPath("lastBuildDate")%>
</ItemTemplate>
</asp:DataList>

But how would I get the <yweather> data (with its attributes) to be
displayed, i.e. from the following XML file:
http://xml.weather.yahoo.com/forecastrss?p=UKXX0052&u=c

Using XPath, as above, does not work for <yweather> and I'm not sure
how this is done!

Best Regards,
Stewart.
 
A

Andy Dingley

Everything works fine while parsing normal lines in the feed like this
(on the aspx page):

<asp:DataList ID="DataList1" runat="server"
DataSourceID="XmlDataSourceEd" Width="523px">
<ItemTemplate>
<%#XPath("title")%><br />
<%#XPath("description")%><br />
<%#XPath("lastBuildDate")%>
</ItemTemplate>
</asp:DataList>

Personally I wouldn't touch this stuff with a bargepole. It's the old
DSO approach, re-hashed with XPath kludged onto it. It still sucks as
much as DSO ever did. You'll have a happier life (and up to 40%
hair-regrowth) if you switch to using XSLT instead.
But how would I get the <yweather> data (with its attributes) to be
displayed, i.e. from the following XML file:
http://xml.weather.yahoo.com/forecastrss?p=UKXX0052&u=c

yweather isn't an element, it's an XML namespace for some elements.
Easy enough with XPath, commonplace with XSLT and XPath, but I've no
idea how to do it in M$oft's ASP/XPath. It's probably easy, I just
don't know how. Try searching MSDN or the SDK help files and looking
for "XPath namespace"
 
S

StewartS

Thanks Andy,

I'm relatively new to all this (hence my simple approach to it!) It
should be fairly straightforward - what I'm trying to - which is to
display a weather summary from the Yahoo feed.

I will get round to learning more about XML/XSLT, it's just that I need
a quick solution to this. (I'm particularly interested in the
hair-regrowth programme!)

I'll have another search on the web on XPath. In the mean time, does
anyone know a quick fix for this?

Cheers,
Stewart.
 
S

saratnathb

DataSourceID="XmlDataSourceEd" Width="523px">
<ItemTemplate>
<%#XPath("//yweather:forecast/@day")%><br />
<%#XPath("//yweather:forecast/@date")%><br />
<%#XPath("//yweather:forecast/@low")%><br />
<%#XPath("//yweather:forecast/@high")%><br />
<%#XPath("//yweather:forecast/@text")%><br />
</ItemTemplate>
</asp:DataList>

(or)

DataSourceID="XmlDataSourceEd" Width="523px">
<ItemTemplate>
<%#XPath("yweather:forecast/@day")%><br />
<%#XPath("yweather:forecast/@date")%><br />
<%#XPath("yweather:forecast/@low")%><br />
<%#XPath("yweather:forecast/@high")%><br />
<%#XPath("yweather:forecast/@text")%><br />
</ItemTemplate>
</asp:DataList>

Not work.

Else try to use MSXML parser method and transform the input XML
document to strip out those yweather prefixes. Let me know if you need
XSLT to do that.
 
S

saratnathb

ok... then it seems like this is not working.
Do then you need to transform the input xml feed and strip it of all
namspace prefixes.

Create save this XSLT as a file and apply it on the input weather feed
before you pass it to your program.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:blush:utput method="xml" indent="no"/>

<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>

Source : http://www.tei-c.org.uk/wiki/index.php/Remove-Namespaces.xsl

Btw. - i am not a msft person. so i do not have much idea on the msft
api to do this.


Buddhiraju Saratnath
http://www.geocities.com/saratnathb
 
A

Andy Dingley

Do then you need to transform the input xml feed and strip it of all
namspace prefixes.

Namespaces are your friend, so use them, don't throw them away!

First of all though you'll need to register that namespace with the
processor (XSLT, or presumably DSO too) This is easy in XSLT, just use
a namespace on the <xsl:stylesheet> element. I don't know how you do it
for DSO, presumably there's an extra statement to use earlier on
 
S

saratnathb

Absolutely!

If you can declare the namespace in your DSO, do use it.
If it doesn't support namespaces, you might have to live with this
kludge!


Saratnath Buddhiraju
 
A

Andy Dingley

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top