Pages: 1 :: [one page] |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |
Louis Vitton
Kickass inc Controlled Chaos
1
|
Posted - 2011.10.03 06:06:00 -
[1] - Quote
Hey guys,
I am having issues trying to parse some of the XML from https://api.eveonline.com/eve/CharacterInfo.xml.aspx?characterID=90926985
Quote: rowset name="employmentHistory" key="recordID" columns="recordID,corporationID,startDate" row recordID="17532403" corporationID="98052700" startDate="2011-08-01 23:47:00" row recordID="17204306" corporationID="1000170" startDate="2011-06-26 15:46:00"
I have removed some of the formatting from here as it would not let me place HTML formatting in this forum.
This section i can not manage to parse, i am using simple xml the same as this code below shows
Quote: < ?php
$data = file_get_contents('https://api.eveonline.com/eve/CharacterInfo.xml.aspx?characterID=90926985'); $xml = new SimpleXMLElement($data); #var_dump($xml);
print $xml->result->{'characterName'}->{0};
? >
Any help you could give me i would be very happy about. Thank you.
Cheers Louis
|
Lutz Major
8
|
Posted - 2011.10.03 06:54:00 -
[2] - Quote
Statement: I don't have any clue regarding PHP, but
guessing: when you can access the node element 'result' by Quote:print $xml->result; why can't you access the element 'characterName' with Quote:print $xml->result->characterName; ?
Also, can it be, that {0} is an accessor for an array? Which clearly the characterName is not? (or does (String){0} return the first character - in your case 'S'?) |
Louis Vitton
Kickass inc Controlled Chaos
1
|
Posted - 2011.10.03 07:58:00 -
[3] - Quote
I can print the charater name i can not print the employment history section |
Lutz Major
8
|
Posted - 2011.10.03 08:20:00 -
[4] - Quote
Louis Vitton wrote:I can print the charater name i can not print the employment history section Apologetically: Sorry, I then misinterpreted your request.
Does Quote:$xml->result->row[0] not work?
or something like Quote: foreach ($xml->result->row as $row) { print $row->corporationID }
|
Louis Vitton
Kickass inc Controlled Chaos
1
|
Posted - 2011.10.03 08:40:00 -
[5] - Quote
No neither seem to work :( |
Lutz Major
8
|
Posted - 2011.10.03 10:03:00 -
[6] - Quote
Thanks to my colleague, who knows I'm incapable of PHP, it's Quote:print $xml->result->rowset->row[0]{'corporationID'}; or Quote:foreach ($xml->result->rowset->row as $row) { print $row{'recordID'}; }
|
Louis Vitton
Kickass inc Controlled Chaos
1
|
Posted - 2011.10.03 15:09:00 -
[7] - Quote
Lutz Major wrote:Thanks to my colleague, who knows I'm incapable of PHP, it's Quote:print $xml->result->rowset->row[0]{'corporationID'}; or Quote:foreach ($xml->result->rowset->row as $row) { print $row{'recordID'}; }
Thank you mate it works now.
I am a complete noob to php and this has been a huge help. :) |
Kossaw
H A V O C Cascade Imminent
2
|
Posted - 2011.10.06 07:43:00 -
[8] - Quote
when you parse XML elements the value often comes back as an array datatype- which cant be printed.
You probably need to force the dataype using (string), (int), (float) etc. For example ......
print (string)$xml->result->rowset->row[0]->characterName; print (int)$xml->result->characterID; |
TorTorden
NorCorp Enterprise No Holes Barred
1
|
Posted - 2011.10.06 23:56:00 -
[9] - Quote
at least with php and simplexml assumes all values are strings. wich is of course fine for echoing, but if you need to do some math with it you must as mentioned type cast them like $x=(double) $xml->something->something...
|
fenistil
1st. Legion HUN Reloaded
0
|
Posted - 2011.10.09 13:29:00 -
[10] - Quote
A Net trick I figured for SimpleXML is this:
Quote: $sXmlObject = simplexml_load_string($xml); $xmlObject = json_decode(json_encode($sXmlObject));
Now all SimpleXMLElement Objects are converted to StdClass objects. Might be easier to use and certainly easier to serialize and store in DB. |
|
Dragonaire
Corax. PURgE Alliance
13
|
Posted - 2011.10.09 15:43:00 -
[11] - Quote
If your going to be storing it in the database in an unprocessed form why not just store the XML directly then you don't have to serialize etc. Finds camping stations from the inside much easier. Designer of Yapeal for Eve API. Check out the Yapeal forum thread |
Louis Vitton
Kickass inc Controlled Chaos
1
|
Posted - 2011.10.09 23:19:00 -
[12] - Quote
Dragonaire wrote:If your going to be storing it in the database in an unprocessed form why not just store the XML directly then you don't have to serialize etc.
Hey Dragonaire,
Do you have any examples of how to do this that i can read up on?
I was going to use your Yapeal coding but there is a lot there i just do not understand yet as i am teaching myself mySql and php as i am building things and going forward slowly. I am an IT student but i study in IT networking not programming but have a real interest in this area for side projects and hobby work like building this API tool I want.
Cheers,
Louis |
Dragonaire
Corax. PURgE Alliance
13
|
Posted - 2011.10.10 01:07:00 -
[13] - Quote
In Yapeal I'm caching the XML in the private method cacheXmlDatabase() which is in class/YapealApiCache.php but it's not complex once you have the XML as a string to pass to over to SimpleXML just do a insert to the database. All you need is a simple table like this:
CREATE TABLE IF NOT EXISTS `utilXmlCache` ( `hash` char(40) CHARACTER SET ascii NOT NULL, `api` char(32) CHARACTER SET ascii NOT NULL, `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `section` varchar(8) COLLATE utf8_unicode_ci NOT NULL, `xml` longtext COLLATE utf8_unicode_ci, PRIMARY KEY (`hash`), KEY `utilXmlCache1` (`section`), KEY `utilXmlCache2` (`api`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
which is directly from Yapeal's DB. The hash I use as primary key is formed from the parameters use to get the XML from CCP server plus some other stuff. You could use something else or even not have it if you're just making a single character test application.
SimpleXML also has methods to return stuff as string or save to file if you prefer. Best places to learn how to do this stuff is the same places I learned from which are the PHP manual online and maybe a few APress or O'Reilly book on using PHP SimpleXML, and MySQL. Most schools give IT students access to a collection of them online for free. Finds camping stations from the inside much easier. Designer of Yapeal for Eve API. Check out the Yapeal forum thread |
|
|
|
Pages: 1 :: [one page] |