How to access and work with XML from API in C#

Posted by Jarek on Stack Overflow See other posts from Stack Overflow or by Jarek
Published on 2010-03-08T05:09:56Z Indexed on 2010/03/08 5:21 UTC
Read the original article Hit count: 315

Filed under:
|
|
|

My goal is to pull XML data from the API and load it to a sql server database. The frist step I'm attempting here is to access the data and display it. Once I get this to work I'll loop through each row and insert the values into a sql server database. When I try to run the code below nothing happens and when I paste the url directly into the browser I get this error

"2010-03-08 04:24:17 Wallet exhausted: retry after 2010-03-08 05:23:58. 2010-03-08 05:23:58"

To me it seems that every iteration of the foreach loop makes a call to the site and I get blocked for an hour. Am I retrieving data from the API in an incorrect manner? Is there some way to load the data into memory or an array then loop through that?

Here's the bit of code I hacked together.

using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string userID = "123";
            string apiKey = "abc456";
            string characterID = "789";
            string url = "http://api.eve-online.com/char/WalletTransactions.xml.aspx?userID=" + userID + "&apiKey=" + apiKey + "&characterID=" + characterID;
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(url);
            XmlNamespaceManager xnm1 = new XmlNamespaceManager(xmldoc.NameTable);
            XmlNodeList nList1 = xmldoc.SelectNodes("result/rowset/row", xnm1);
            foreach (XmlNode xNode in nList1)
            {
                Response.Write(xNode.InnerXml + "<br />");
            }
        }

        catch (SqlException em)
        {
            Response.Write(em.Message);
        }
    }
}

Here's a sample of the xml

<eveapi version="2"> 
  <currentTime>2010-03-06 17:38:35</currentTime> 
  <result> 
    <rowset name="transactions" key="transactionID" columns="transactionDateTime,transactionID,quantity,typeName,typeID,price,clientID,clientName,stationID,stationName,transactionType,transactionFor"> 
      <row transactionDateTime="2010-03-06 17:16:00" transactionID="1343566007" quantity="1" typeName="Co-Processor II" typeID="3888" price="1122999.00" clientID="1404318579" clientName="unseenstrike" stationID="60011572" stationName="Osmeden IX - Moon 6 - University of Caille School" transactionType="sell" transactionFor="personal" /> 
      <row transactionDateTime="2010-03-06 17:15:00" transactionID="1343565894" quantity="1" typeName="Co-Processor II" typeID="3888" price="1150000.00" clientID="1404318579" clientName="unseenstrike" stationID="60011572" stationName="Osmeden IX - Moon 6 - University of Caille School" transactionType="sell" transactionFor="personal" /> 
    </rowset> 
  </result> 
  <cachedUntil>2010-03-06 17:53:35</cachedUntil> 
</eveapi>

© Stack Overflow or respective owner

Related posts about Xml

Related posts about c#