These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

Help with AllianceList XML feed (stuck n00b alert!)

Author
Teasel
Serenity Logistics Corporation
#1 - 2015-09-09 13:11:50 UTC  |  Edited by: Teasel
Hi All,

I'm hoping someone can help me with the following problem. I'm pretty new to the API and parsing the XML output. I have managed to get the results I need from the rest of the API calls I'm making but I'm getting stuck with the AllianceList Xml. For those who have not looked at this monster XML file, here's a hugely truncated example to show the layout of it:

(Angle braces removed from xml example)
=======================================================================================

eveapi version="2"
    currentTime 2015-09-09 12:39:58 /currentTime
    result
         rowset name="alliances" key="allianceID" columns="name,shortName,allianceID,executorCorpID,memberCount,startDate"
             row name="Goonswarm Federation" shortName="CONDI" allianceID="1354830081" executorCorpID="1344654522" memberCount="14001" startDate="2010-06-01 05:36:00"
                 rowset name="memberCorporations" key="corporationID" columns="corporationID,startDate"
                     row corporationID="98000377" startDate="2015-09-01 04:35:00"/
                     row corporationID="98002506" startDate="2014-11-12 22:20:00"/
                     row corporationID="98007214" startDate="2012-01-28 05:36:00"/
                     row corporationID="98008630" startDate="2010-12-20 19:40:00"/
                     row corporationID="98014536" startDate="2011-01-16 15:45:00"/
                    etc...
                 /rowset
             /row
             row name="Brave Collective" shortName="BRAVE" allianceID="99003214" executorCorpID="98199293" memberCount="12464" startDate="2013-05-06 22:20:14"
                 rowset name="memberCorporations" key="corporationID" columns="corporationID,startDate"
                 row corporationID="1818800266" startDate="2015-01-14 00:43:00"/
                 row corporationID="1857499356" startDate="2013-12-28 23:06:00"/
                 row corporationID="781729299" startDate="2013-12-10 22:55:00"/
                etc...
             /rowset
             /row
            etc...
         /rowset
     /result
     cachedUntil 2015-09-09 13:11:51 /cachedUntil
/eveapi

=======================================================================================

...My problem is that I have written a script that pulls just the alliance info from the "alliances" rowset and that works great. However, I can't seem to get the "memberCorporations" data from it's rowset. I am using simplexml to parse the api feed but can't seem to access the member corp info. The (working) script I have written is:


//Retrieve the MASSIVE AllianceList.xml file and parse it.
$alinfo = simplexml_load_file('https://api.eveonline.com/Eve/AllianceList.xml.aspx');

//get alliance info
foreach($alinfo->result->rowset[0] as $row){
    $alnm = $row['name'];
    $shnm = $row['shortName'];
    $alid = $row['allianceID'];
    $exid = $row['executorCorpID'];
    $meco = $row['memberCount'];
    $stdt = $row['startDate'];
    $cpid = $row['corporationID'];
    
    //echo results for now...
    echo' '.$alnm.' '.$shnm.' '.$alid.' '.$exid.' '.$meco.' '.$stdt.' '.$cpid.' ';
}


This displays the alliance info (i am echoing at the moment as I am still testing it but eventually the script will insert the info into a mySQL DB table. The (non-working) script is a variation of the alliance one:


//get member corp info
foreach($alinfo->result->rowset[1] as $mem){
    $corpID = $mem['corporationID'];
    $joined = $mem['startDate'];
    
    //echo results for now...
    echo''.$corpid.' '.$joined.'';
}


I am assuming that since the member corp info is on a different rowset that the rowset index is [1]. However, this doesn't seem to work. i have tried other ways of getting this info (xpath etc) but would like to keep things simple for now. What is it that I need to do with the script to make it work? When I var_dump the $alinfo variable, the array contains the corp info but I can't access it -help, it's doing my head in! :(
Samuel Sachs
#2 - 2015-09-09 17:59:01 UTC
I dont understand exactly what you try to do, which string you looking for and what is your way to pull datas, sheets or what ?

SheetMon_V2 a gdocs spreadsheet what pulls lots of stuff, feel free to make a copy :-)

Ydnari
Estrale Frontiers
#3 - 2015-09-09 18:18:20 UTC
Do it inside the first loop where it'll be $row->rowset[0].

--

Teasel
Serenity Logistics Corporation
#4 - 2015-09-09 18:18:55 UTC
Samuel Sachs wrote:
I dont understand exactly what you try to do, which string you looking for and what is your way to pull datas, sheets or what ?

I am creating a database with two tables (alliance, members) and populating each with the relevant info (using the allianceID as an access key for the members table). I have already successfully tested the variables to populate the 'alliance' table so this isn't a problem.

The problem I'm having is that I am looking to get the information from the "memberCorporations" rowset from the alliance sheet (the corpID and startDate) info. This side of things is not working.

I am pulling the data using the simplexml php method and currently outputting the info on screen via 'echo' (populating a variable for each category ($corpid = 'corporationID', $joined = 'startDate'). Eventually the info will be written to a database table but for now I am displaying the info so I can verify that the variables are being populated with the required info.
Teasel
Serenity Logistics Corporation
#5 - 2015-09-09 18:20:09 UTC
Ydnari wrote:
Do it inside the first loop where it'll be $row->rowset[0].

Thanks, I'll give that a whirl :)
Teasel
Serenity Logistics Corporation
#6 - 2015-09-09 18:23:31 UTC
Ydnari wrote:
Do it inside the first loop where it'll be $row->rowset[0].

Brilliant! Works a treat! Thanks so much (that was probably the only thing I didn't try lol) Lol
Yogi Berimor
State War Academy
Caldari State
#7 - 2015-09-10 00:15:52 UTC  |  Edited by: Yogi Berimor
Why are you parsing it yourself in the first place?
Use PhealNG, don't be a scrub. It handles all the boring stuff. Moreover, it also supports local result caching so you never hit the limit.

Library itself: https://github.com/3rdpartyeve/phealng
Symfony2 Bundle: https://github.com/EvELabs/EvelabsPhealNGBundle
Teasel
Serenity Logistics Corporation
#8 - 2015-09-10 12:05:31 UTC
I am parsing it myself because I am teaching myself how to parse xml.
Yogi Berimor
State War Academy
Caldari State
#9 - 2015-09-11 00:45:02 UTC  |  Edited by: Yogi Berimor
Teasel wrote:
I am parsing it myself because I am teaching myself how to parse xml.

In this case i suggest you read about Xpath.

http://php.net/manual/en/simplexmlelement.xpath.php
http://www.w3schools.com/php/func_simplexml_xpath.asp
http://www.dimuthu.org/blog/2008/09/30/xpath-in-simplexml/
http://www.w3.org/TR/xpath/

So basically, you use Xpath to navigate to the element or even subtree and then work with them instead of having to work with entire document.

Also there is shorter version of AllianceList endpoint available: https://api.eveonline.com/eve/AllianceList.xml.aspx?version=1
Dragonaire
Here there be Dragons
#10 - 2015-09-11 07:11:15 UTC
You might also have a look at how I parse that API in Yapeal as well to learn some other ways to work with XML in PHP.

Finds camping stations from the inside much easier. Designer of Yapeal for the Eve API. Check out the Yapeal PHP API Library thread.

Teasel
Serenity Logistics Corporation
#11 - 2015-09-11 07:54:38 UTC
Yogi Berimor wrote:
Teasel wrote:
I am parsing it myself because I am teaching myself how to parse xml.

In this case i suggest you read about Xpath.

http://php.net/manual/en/simplexmlelement.xpath.php
http://www.w3schools.com/php/func_simplexml_xpath.asp
http://www.dimuthu.org/blog/2008/09/30/xpath-in-simplexml/
http://www.w3.org/TR/xpath/

So basically, you use Xpath to navigate to the element or even subtree and then work with them instead of having to work with entire document.

Also there is shorter version of AllianceList endpoint available: https://api.eveonline.com/eve/AllianceList.xml.aspx?version=1


Dragonaire wrote:
You might also have a look at how I parse that API in Yapeal as well to learn some other ways to work with XML in PHP.


Thank-you both for the advice (and links), It's much appreciated :) I will look further into xpath and Yapeal as I progress....