• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 691
  • Last Modified:

RSS feed in C# - get exchange rates

How do I get the exchange rate from this rss feed? http://www.rba.gov.au/rss/rss-cb-exchange-rates.xml

Void GetExchangeRate (string CurrencyCode, out Decimal ReturnRate, out DateTime ReturnDateTime)
{

//Do something...

//Return the Rate and DateTime


}
0
RobertChanphakeo
Asked:
RobertChanphakeo
1 Solution
 
myaspnetCommented:

<MARQUEE  id="ml"  runat="server"  style="PADDING-TOP: 2px" onmouseover=" this.stop()" onmouseout=this.start() direction=right height=24 width="100%" scrollAmount=4><SPAN class=sep>¿¿¿¿¿¿¿.¿¿</SPAN></MARQUEE>
 
 
Public Partial Class arabiaNews
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        newsarabia()
    End Sub
 
    Sub newsarabia()
        Dim ds As New Data.DataSet
        Dim strRss As String = Server.MapPath("Intranet/arabiaRss.xml")
        ds.ReadXml(strRss)
        If ds.Tables.Count > 0 Then
            If ds.Tables(3).Rows.Count > 0 Then
                For i As Integer = 0 To ds.Tables(3).Rows.Count - 1
                    Dim NewTitle As String = ds.Tables(3).Rows(i)("title")
                    Dim url As String = ds.Tables(3).Rows(i)("link")
                    Dim lnk As New HtmlAnchor 'With {.InnerHtml = NewTitle, .HRef = url, .Target = "_blank"}
                    lnk.InnerHtml = NewTitle
                    lnk.HRef = url
                    lnk.Target = "_blank"
                    ml.Controls.Add(lnk)
                    ml.Controls.Add(New LiteralControl("&nbsp;&nbsp;&nbsp;"))
                Next
            End If
        End If
    End Sub
End Class

Open in new window

0
 
brutaldevCommented:
You could go the route of loading the response into an XDocument or XmlReader and parsing out what you need manually. Bu a better approach would be to use an RSS parser meant for the job.

This is a good example of how to parse RSS feeds, you should be able to extract the required values easily using this: http://www.shrinkrays.net/code-snippets/csharp/simplified-csharp-atom-and-rss-feed-parser.aspx. There are also links to other feebie RSS parsers if this simple one does not cater for your needs.
0
 
Asim NazirCommented:
You can use xPath, xQuery or Linq to xml for parsing purposes. Sample c# code using xPath would be like this:

 
public static string GetRSSFeedDataSource(string url)
    {
        XmlTextReader feedreader = null;
        XmlDocument feedDocument = null;
        string sFeedString = string.Empty;
        try
        {

            feedreader = new XmlTextReader(url);
            
            // Get basic feed document
            feedDocument = new XmlDocument();
            feedDocument.Load(feedreader);

            String sParsedValue = string.Empty;

            // Create a navigator to query with XPath.
            XPathNavigator nav = feedDocument.CreateNavigator();

            string namespaceUri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
            XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
            ns.AddNamespace("ns", namespaceUri);
            try
            {
                XPathNodeIterator iterator = nav.Select("/rdf", ns); // update xPath expression
                foreach (XPathNavigator item in iterator)
                {
                    // Get value for the selected expression
                    sParsedValue = item.Value;                    
                }
            }
            catch { }
        }
        catch (Exception)
        {
           
        }

        return sFeedString;
    }

Open in new window


I hope it helps.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now