Pages: [1] :: one page |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |
Sion Corbulio
|
Posted - 2009.08.03 00:01:00 -
[1]
I am messing around with the EVE API stuff and really need some help. So far I have managed to submit my apikey and userid and have the returned XML store in a PHP variable. So when I echo the variable it now shows all my XML.
This looks nice, but what do I actually do with it now to make it display only certain elements from the XML? I have tried reading into XML parsing but all the tutorials I have found so far only deal with XML files. I can't seem to find anything regarding simply messing about with the XML when it is already in a variable. Is this even considered to be XML? Certainly when I echo it on screen it behaves like any other XML!
Some advice would be appreciated!
Thanks |
Johnathan Roark
Caldari Quantum Industries RAZOR Alliance
|
Posted - 2009.08.03 01:06:00 -
[2]
Edited by: Johnathan Roark on 03/08/2009 01:14:00 xpath and simpleXML
A PHP API example
There are also some php libraries for the api such as Yapeal and ale that make the api easier to work with.
Quantum Industries is recruiting! |
Dragonaire
Caldari Corax. New Eden Retail Federation
|
Posted - 2009.08.03 08:21:00 -
[3]
Like he said above you'll want to use either DOM or SimpleXML to make it into an object where you can actually do something with it otherwise it's just a big string and not very nice to work with -- Finds camping stations from the inside much easier. Designer of Yapeal for Eve API.
|
Creesch
Under the Wings of Fury Atrocitas
|
Posted - 2009.08.03 09:16:00 -
[4]
Edited by: Creesch on 03/08/2009 09:22:04 Ok lets do a simple example (although not being a developer I had trouble the first time as well). Say you want to know wich corps a person is in for website validation
// first we'll actually request the right api url from the eve api website and instert this in simplexml, notice the api variables $request_url = "http://api.eve-online.com/account/Characters.xml.aspx?apiKey=$apiKey&userid=$userid"; $xml = simplexml_load_file($request_url) or die("feed not loading");
// Since the data is all in attributes we have to load that, we are going for the corp id, for this example I use a array with some corp ids to check against $ok=0; $alliancecorpids=array(1234,5778,844434); foreach($xml->result->rowset->row as $charcorpid) {
if (in_array($charcorpid[ "corporationID" ],$alliancecorpids)) $ok=1;
}
// Ok now we can check if the user is indeed in one of the corps that is in the array. if ($ok==1){
// do some code here to get the user validated for your forum or something } else {
// or let the script die if he isn't (or loop it if you want to check more users) if (!$ok) die('<br> helaas'); }
Url to pastebin for more readable code
This is fairly easy, but what if you want to know what corps are in a certain alliance? Would be handy ofcourse to automatically fill that array we used earlier.
// we are using a slightly different aproach here to load in the xml file since we want to play with xpath (xpath can do queries on xml $xmldoc = new DOMDocument(); $xmldoc->load('http://api.eve-online.com/eve/AllianceList.xml.aspx');
$xpathvar = new Domxpath($xmldoc);
// lets go ahead and create the array $alliancecorpids= array();
// the actual xpath variable is in here, basically we do a SELECT alliance FROM xmlfile WHERE allianceID = 1234 $alliance = $xpathvar->query("/eveapi/result/rowset/row[@allianceID = '1234']/rowset/row/@corporationID"); foreach($alliance as $corpresult){
// put the results in the array and we are done.
$alliancecorpids[]=$corpresult->nodeValue;
}
Url to pastebin for more readable code
one thing though, this all does require php5, php4 doesn't have very good xml parsing so would require external libaries :)
[DISCLAIMER] I am no php developer at all and have limited knowledge about creating effective coding. This is code I used for my forum registration script I came up after googling for a few days and bugging real developers with questions. It works for me but it might very well be that I am making things here and there more complicated than they really need to be. As far as the whole script goes, it is made for a phpbb forum but could easily be adapted to any forum system since it operates seperate from the installation but instead directly edits the db (this because of my experience with mods that break with every new version of forum softwarE). If anyone is interested i'll be happy to share the code, just drop me a evemail
____ Hi! |
Lumy
Minmatar Sebiestor tribe
|
Posted - 2009.08.03 10:01:00 -
[5]
Have a look at Ale. Sourceforge link. The library has specialized parser class for EVE API. It's wrapper around SimpleXMLElement, but allow you to address rowset ellements by their name attribute. Also allows you to iterate through them as if they were arrays. And some more fancy stuff.
Joomla! in EVE - IGB compatible CMS. |
Steven Dark
|
Posted - 2009.08.03 15:09:00 -
[6]
Hey!
There is also a light weight framework called fluentDom. You can use it like jquery on your xml. Check it out at the fluentDom homepage http://www.fluentdom.org/
|
Sion Corbulio
|
Posted - 2009.08.03 15:48:00 -
[7]
Thanks guys nice responses! I will look through them. |
Sion Corbulio
|
Posted - 2009.08.03 16:10:00 -
[8]
Okay I got it working! Wow it is pretty simple. I have extensive PHP knowledge, but not worked with XML before. It looks nice though, starting to see the benefits.
Thanks once again peeps. |
|
|
|
Pages: [1] :: one page |
First page | Previous page | Next page | Last page |