I'm working with the XMLSOCCER API which produces an XML response with the data.
They have a .NET library to work with their data.
var x = Client.GetAllLeagues(ApiKey);
XmlNodeList list = x.ChildNodes;
GetAllLeagues(string ApiKey) returns an XMLNode which is the root of the response:
<?xml version="1.0" encoding="UTF-8"?>
<XMLSOCCER.COM>
<League>
<Id>1</Id>
<Name>English Premier League</Name>
<Country>England</Country>
<Historical_Data>Yes</Historical_Data>
<Fixtures>Yes</Fixtures>
<Livescore>Yes</Livescore>
<NumberOfMatches>5640</NumberOfMatches>
<LatestMatch>2015-04-13T21:00:00+00:00</LatestMatch>
</League>
<League>
<Id>2</Id>
<Name>English League Championship</Name>
<Country>England</Country>
<Historical_Data>Yes</Historical_Data>
<Fixtures>Yes</Fixtures>
<Livescore>Yes</Livescore>
<NumberOfMatches>8335</NumberOfMatches>
<LatestMatch>2015-04-17T20:45:00+00:00</LatestMatch>
</League>
</XMLSOCCER.COM>
I can get to the Nodes and their values with the following:
for (var i = 0; i < list.Count; i++ )
{
var children = list.Item(i).ChildNodes;
for(var j=0; j < children.Count; j++ ){
Console.WriteLine(String.Format("Key:{0} Value:{1}", children.Item(j).Name, children.Item(j).InnerText));
}
}
The problem I'm facing is that this feels largely inefficient. If I could use XmlReader it might make it easier to work with. But since XmlReader.Create(); Expects a Stream, I can't work with the XmlNode that the API returns.
I thought I could use the example from the following: http://ift.tt/1GYQ2GA
How would you parse the data?
No comments:
Post a Comment