Jump to content

SimpleXML Help


residual

Recommended Posts

Need some help parsing an item using simplexml, the problem I have is the item is not in a channel and/or is numeric.  I want to parse out Gamerscore but as you can see it isn't in a channel.  I know the normal syntax for simplexml is feed-channel-item but feed-item only returns 0 instead of the number.

 

XML:

  <?xml version="1.0" ?> 
- <XboxInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <AccountStatus>Gold</AccountStatus> 
- <PresenceInfo>
  <Valid>true</Valid> 
  <Info>Last seen 13 hours ago playing Halo 3</Info> 
  <Info2 /> 
  <LastSeen>2008-07-15T20:50:52-05:00</LastSeen> 
  <Online>false</Online> 
  <StatusText>Offline</StatusText> 
  <Title>Halo 3</Title> 
  </PresenceInfo>
  <State>Valid</State> 
  <Gamertag>OcR Envy</Gamertag> 
  <ProfileUrl>http://live.xbox.com/member/OcR Envy</ProfileUrl> 
  <TileUrl>http://tiles.xbox.com/tiles/X3/MG/0Gdsb2JhbC9ECgRcBxwAGABaL3RpbGUvMC8yODAwMAAAAAAAAAD-KXN-.jpg</TileUrl> 
  <Country>United States</Country> 
  <Reputation>99.7379</Reputation> 
  <Bio>www.outcastreborn.com Visit today to apply or to challenge us to a match!</Bio> 
  <Location>Quincy, MA</Location> 
  <ReputationImageUrl>http://live.xbox.com/xweb/lib/images/gc_repstars_external_20.gif</ReputationImageUrl> 
  <GamerScore>2090</GamerScore> 
  <Zone>Underground</Zone> 
</XboxInfo>

 

My script:

$fetch_url = "http://duncanmackenzie.net/services/GetXboxInfo.aspx?GamerTag=" . urlencode($h3tag);

 

$userinfo=screen_scrape("$fetch_url");

$xml = simplexml_load_string($userinfo);

 

$tagvalid=$xml->PresenceInfo->Valid;

$onlinestatus=$xml->PresenceInfo->Online;

$statustext=$xml->PresenceInfo->StatusText;

$title=$xml->PresenceInfo->Title;

$info=$xml->PresenceInfo->Info;

$info2=$xml->PresenceInfo->Info2;

$lastseen=$xml->PresenceInfo->LastSeen;

$gamerscore=$xml->GamerScore;

 

Everything returns fine excluding $gamerscore which always returns a 0, please help!

Link to comment
https://forums.phpfreaks.com/topic/115057-simplexml-help/
Share on other sites

It isn't inside PresenceInfo, as it turns out there are more than one gamerscore items(see below), I assume I need a loop of some kind, any help guys?

 

−
<XboxInfo>
<AccountStatus>Gold</AccountStatus>
−
<PresenceInfo>
<Valid>true</Valid>
<Info>Last seen 13 minutes ago playing Halo 3</Info>
<Info2/>
<LastSeen>2008-07-16T17:48:40-05:00</LastSeen>
<Online>false</Online>
<StatusText>Offline</StatusText>
<Title>Halo 3</Title>
</PresenceInfo>
<State>Valid</State>
<Gamertag>OcR Envy</Gamertag>
<ProfileUrl>http://live.xbox.com/member/OcR Envy</ProfileUrl>
−
<TileUrl>
http://tiles.xbox.com/tiles/X3/MG/0Gdsb2JhbC9ECgRcBxwAGABaL3RpbGUvMC8yODAwMAAAAAAAAAD-KXN-.jpg
</TileUrl>
<Country>United States</Country>
<Reputation>99.71587</Reputation>
−
<Bio>
         www.outcastreborn.com               Visit today to apply or to challenge us to a match!
</Bio>
<Location>Quincy, MA</Location>
−
<ReputationImageUrl>
http://live.xbox.com/xweb/lib/images/gc_repstars_external_20.gif
</ReputationImageUrl>
<GamerScore>2090</GamerScore>
<Zone>Underground</Zone>
−
<RecentGames>
−
<XboxUserGameInfo>
−
<Game>
<Name>Halo 3</Name>
<TotalAchievements>49</TotalAchievements>
<TotalGamerScore>1000</TotalGamerScore>
−
<Image32Url>
http://tiles.xbox.com/tiles/oo/P5/0mdsb2JgbA9ECgR8GgMfWSpVL2ljb24vMC84MDAwIAABAAAAAP3Wg70=.jpg
</Image32Url>
−
<Image64Url>
http://tiles.xbox.com/tiles/zS/3N/1Wdsb2JhbC9ECgR8GgMfWSpVL2ljb24vMC84MDAwAAAAAAAAAPriLdI=.jpg
</Image64Url>
</Game>
<LastPlayed>2008-07-16T14:41:38-05:00</LastPlayed>
<Achievements>42</Achievements>
<GamerScore>905</GamerScore>
−
<DetailsURL>
http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3a%15%18*iAr%07&compareTo=OcR+Envy
</DetailsURL>
</XboxUserGameInfo>

Link to comment
https://forums.phpfreaks.com/topic/115057-simplexml-help/#findComment-592062
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.