This is just a hunch, but if you try to access that URI more frequently than 60 seconds, you get the following message returned:
`Please use a minimum interval of 60 sec (please wait for 10,65625 sec).`
Since this response is clearly not XML, the XmlReader
can't do anything with it.
I'm able to successfully run your code as long as there's 60 seconds or more between connections.
A couple of things to add:
Your if condition is not going to get the nodes you are looking for - XML is case-sensitive. It should be like this:
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "OO"))
LINQ to XML would be an easier (in my mind) way of doing this:
LINQ to XML Example
using System.Xml.Linq;
// This loads the XML from the specified URI into the XDocument
XDocument xDoc = XDocument.Load("http://www.bet-at-home.com/oddxml.aspx");
// This query will return a collection of all the "OO" elements (and their children)
var oo = from x in xDoc.Descendants("OO")
select x;
// You can iterate through this collection and do what you want
foreach (XElement ele in oo)
{
// do something with each OO group
}
Alternatively, you could return an anonymous type (or a defined type) from the query. For example:
var oo = from x in xDoc.Descendants("OO")
select new
{
Sport = x.Element("Sport").Value,
Category = x.Element("Category").Value,
Tournament = x.Element("Tournament").Value,
Date = x.Element("Date").Value
// and so on
};
You would then have a collection of these anonymous types that you could iterate through.
If you had a class defined that you wanted to hold data in (say BettingOdds), you'd simply use that instead and the select new
line would become select new BettingOdds
.
Note that you'll need to check to ensure that the elements you're referring to exist, otherwise you'll get a null reference exception.
There's a ton of examples on what you can do with LINQ to XML on the internet - here's an example - LINQ To XML Tutorials with Examples