Solved: Trouble pulling item statistics from the armory

Here you can find plenty of help with your general coding needs and projects
If it is about a specific program, use the corresponding forum
DO NOT ask basic questions such as "How do I print a variable", use Google for that

Solved: Trouble pulling item statistics from the armory

Postby Gaxme » Mon Mar 16, 2009 8:35 pm

Has anyone had any luck pulling items from the armory lately? I have been trying to figure out why I cannot extract item statistics to store. The XML I am getting from the armory looks as follows:

Code: Select all
 SimpleXMLElement object(
   '@attributes' =>  Array(
      'globalSearch' => 1,
      'lang' => 'en_us',
      'requestQuery' => 'i=28608',
      'requestUrl' => '/item-info.xml'
      ),
   'itemInfo' =>  SimpleXMLElement object(
      'item' =>  SimpleXMLElement object(
         '@attributes' =>  Array(
            'icon' => 'inv_boots_plate_04',
            'id' => 28608,
            'level' => 115,
            'name' => 'Ironstriders of Urgency',
            'quality' => 4,
            'type' => 'Plate'
            ),
         'cost' =>  SimpleXMLElement object(
            '@attributes' =>  Array(
               'sellPrice' => 63623
               )
            ),


Most of my code structures attempt to pull this way (pseudo code)
Code: Select all
$icon = $itemInfo->item->attributes->icon;
$name = $itemInfo->item->attributes->name;

etc.

However, it fails to actually extract, probably due to the @ symbol in the XML structure. Does anyone have a workaround for this? I guess I may just not know how to escape that character in an object...
Last edited by Gaxme on Tue Mar 17, 2009 7:37 pm, edited 1 time in total.
Gaxme
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 74
Joined: Mon Jul 10, 2006 3:54 am

Trouble pulling item statistics from the armory

Postby PleegWat » Mon Mar 16, 2009 8:49 pm

Hm, Doesn't it use array syntax for attributes?

Code: Select all
$itemInfo->item['icon']
I <3 /bin/bash
User avatar
PleegWat
WoWRoster.net Dev Team
WoWRoster.net Dev Team
 
Posts: 1636
Joined: Tue Jul 04, 2006 1:43 pm

Re: Trouble pulling item statistics from the armory

Postby Gaxme » Mon Mar 16, 2009 9:46 pm

PleegWat wrote:Hm, Doesn't it use array syntax for attributes?

Code: Select all
$itemInfo->item['icon']


Well, looking at the data struct, since item is an object, and it has "@attributes" below it, I'd think it should be

Code: Select all
$itemInfo->item->@attributes['icon']


to work that way, but it doesn't like the "@".
Gaxme
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 74
Joined: Mon Jul 10, 2006 3:54 am

Re: Trouble pulling item statistics from the armory

Postby Gaxme » Mon Mar 16, 2009 10:14 pm

Ok, I did some more digging. Basically if I convert the object variables to an array, I can handle them that way:

Code: Select all
$temp = get_object_vars($itemInfo->item);
$this->icon = $temp['@attributes']['icon'];
$this->name = $temp['@attributes']['name'];


etc.

Not the most elegant, but it works.
Gaxme
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 74
Joined: Mon Jul 10, 2006 3:54 am

Trouble pulling item statistics from the armory

Postby Ulminia » Tue Mar 17, 2009 10:23 am

with the new armory sync being finished item handeling and retreving will be easier ... trust me ... lol
Ulminia of Zangarmarsh
Zonous of Zangarmarsh
Author of Roster Gallery
WoWRoster-Profiler Redesigner
User avatar
Ulminia
WoWRoster.net Dev Team
WoWRoster.net Dev Team
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 1223
Joined: Tue Jul 04, 2006 4:41 pm
Location: New Brunswick, Canada
Realm: Zangarmarsh (PvE) - US
gmail/gtalk: ulminia@gmail.com

Re: Trouble pulling item statistics from the armory

Postby Gaxme » Tue Mar 17, 2009 7:35 pm

I completely forgot to post here for completeness.

PleegWat noted for me that the XML parser in PHP handles references in the background. So you can actually pull itemInfo->item['icon'] and get a result. The only difficulty there is if there is more than one "icon" field, you'll only get the first result. (For my purposes this is fine, if someone was pulling the "disenchant" segment of an item struct, it would be more difficult.)

Additionally, you can map to abnormally-named fields with the following syntax:
Code: Select all
itemInfo->item->{'@attributes'}


Handy thing to remember.
Gaxme
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 74
Joined: Mon Jul 10, 2006 3:54 am

Solved: Trouble pulling item statistics from the armory

Postby Ulminia » Tue Mar 17, 2009 11:07 pm

indeed exspecialy when this is how as uses data now
Ulminia of Zangarmarsh
Zonous of Zangarmarsh
Author of Roster Gallery
WoWRoster-Profiler Redesigner
User avatar
Ulminia
WoWRoster.net Dev Team
WoWRoster.net Dev Team
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 1223
Joined: Tue Jul 04, 2006 4:41 pm
Location: New Brunswick, Canada
Realm: Zangarmarsh (PvE) - US
gmail/gtalk: ulminia@gmail.com


Return to General Code Help

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron