locked
xml feed RRS feed

  • Question

  • User-357918778 posted

    Hi i have a weather feed i need to get items from, i have tried using the XmlTextReader but the value property is always empty,

    what i need is everything under the node "current_condition" would be nice if i can just write these straight out to labels, so if a node is a child of "current_condition" then display them

    any ideas?

    Tuesday, January 19, 2010 9:43 AM

Answers

  • User1835330922 posted

    Here is an ASP.NET example using an XmlDataSource to select all child elements of the current_condition element and then output them in a DataList:

            <asp:XmlDataSource ID="wf1" runat="server" DataFile="http://www.worldweatheronline.com/feed/weather.ashx?q=le17%204fn&format=xml&num_of_days=2&key=4a4f6c7f85110041101901"
                XPath="data/current_condition/*"></asp:XmlDataSource>
            <asp:ListView ID="wl1" runat="server" DataSourceID="wf1">
                <LayoutTemplate>
                    <table>
                        <thead>
                            <tr>
                                <th>name</th>
                                <th>value</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr id="itemPlaceholder" runat="server"/>
                        </tbody>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr runat="server">
                        <td>
                            <%#XPath("name()") %>
                        </td>
                        <td>
                            <%#XPath(".") %>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:ListView>


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 20, 2010 7:34 AM

All replies

  • User1835330922 posted

    Without seeing the markup of the feed or at least the URL of the feed there is not much we can suggest. .NET has several APIs to deal with XML, with .NET 3.5 for RSS 2.0 and Atom 1.0 feeds you should use http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed.aspx, for other XML format LINQ to XML is a generic API. With earlier versions you can use System.Xml.XmlDocument or even System.Xml.XPath.XPathDocument/XPathNavigator if you only need readonly access.

    Tuesday, January 19, 2010 10:44 AM
  • User-357918778 posted

    Many thanks the feed url is
    http://www.worldweatheronline.com/feed/weather.ashx?q=le17 4fn&format=xml&num_of_days=2&key=4a4f6c7f85110041101901


    Wednesday, January 20, 2010 4:39 AM
  • User1835330922 posted

    Here is an ASP.NET example using an XmlDataSource to select all child elements of the current_condition element and then output them in a DataList:

            <asp:XmlDataSource ID="wf1" runat="server" DataFile="http://www.worldweatheronline.com/feed/weather.ashx?q=le17%204fn&format=xml&num_of_days=2&key=4a4f6c7f85110041101901"
                XPath="data/current_condition/*"></asp:XmlDataSource>
            <asp:ListView ID="wl1" runat="server" DataSourceID="wf1">
                <LayoutTemplate>
                    <table>
                        <thead>
                            <tr>
                                <th>name</th>
                                <th>value</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr id="itemPlaceholder" runat="server"/>
                        </tbody>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr runat="server">
                        <td>
                            <%#XPath("name()") %>
                        </td>
                        <td>
                            <%#XPath(".") %>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:ListView>


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 20, 2010 7:34 AM
  • User-357918778 posted

    Hi i have tried your code but i get an error on <%#XPath("name()") %>

    not used xpath before can you help

    thanks

    Friday, January 22, 2010 4:15 AM
  • User2115139740 posted

    <%#XPath("name()") %>

                  change to

    <%#XPath("name") %>

    remove open and close bracket, just try out that ......


    Friday, January 22, 2010 4:26 AM
  • User-357918778 posted

    ok thanks that does work, now i need to only pull out certain values ie how would i just get the value for the node "weatherDesc"

    Friday, January 22, 2010 4:32 AM
  • User1835330922 posted

    Which error exactly do you get? Have you changed anything else? Please post enough code to allow us to reproduce the error.

    Friday, January 22, 2010 6:40 AM
  • User1451399559 posted

    Is it possible to use the XmlDataSource control when the feed has a namespace? I have an atom feed that has a number of namespaces included and I need to define a namespace.


    Scott Hansleman said (in 2005) it wasn't supported, and I can't find a way to do it, so I'm wondering if it is possible?


    Johnny

    Wednesday, February 10, 2010 6:41 PM