Foros del Web » Programando para Internet » PHP »

Listar informacion de un xml

Estas en el tema de Listar informacion de un xml en el foro de PHP en Foros del Web. Amigos tengo el siguiente xml Cita: <?xml version="1.0" encoding="iso-8859-1"?> <qstat> <server type="A2S" address="xxxxxxxx:xxxx" status="UP"> <hostname>201.238.222.78:27032</hostname> <name>Nombre del Servidor</name> <gametype>cstrike</gametype> <map>de_dust2</map> <numplayers>6</numplayers> <maxplayers>26</maxplayers> <ping>9</ping> <retries>0</retries> <players> ...
  #1 (permalink)  
Antiguo 02/02/2010, 01:06
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 16 años
Puntos: 12
Listar informacion de un xml

Amigos tengo el siguiente xml

Cita:
<?xml version="1.0" encoding="iso-8859-1"?>
<qstat>
<server type="A2S" address="xxxxxxxx:xxxx" status="UP">
<hostname>201.238.222.78:27032</hostname>
<name>Nombre del Servidor</name>
<gametype>cstrike</gametype>
<map>de_dust2</map>
<numplayers>6</numplayers>
<maxplayers>26</maxplayers>
<ping>9</ping>
<retries>0</retries>
<players>
<player>
<name>*[T]he [X]ixo*</name>
<score>3</score>
<time> 1h19m 4s</time>
</player>
<player>
<name>|-Galactic Kings-|Vicho</name>
<score>0</score>
<time> 23m19s</time>
</player>
<player>
<name>Flechaaa |</name>
<score>5</score>
<time> 23m23s</time>
</player>
<player>
<name>me pica el ollo</name>
<score>0</score>
<time> 22m 9s</time>
</player>
<player>
<name>zirOne!!</name>
<score>1</score>
<time> 1h 7m 5s</time>
</player>
<player>
<name>zeNNNeK;</name>
<score>0</score>
<time> 21m29s</time>
</player>
</players>

</server>
</qstat>
Lo que necesito es listar los jugadores de la siguiente forma.

Nombre Frags Tiempo
zeNNNeK; 0 21m29s

asi con todos los players que aparescan en el xml.

¿como lo puedo hacer?

Desde ya muchas gracias.
  #2 (permalink)  
Antiguo 02/02/2010, 01:07
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Listar informacion de un xml

puedes utilizar la extensión de PHP SimpleXML

consulta el manual
http://php.net/simplexml
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 02/02/2010, 01:29
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 16 años
Puntos: 12
Respuesta: Listar informacion de un xml

sip, pero para hacer algo como un ciclo foreach
  #4 (permalink)  
Antiguo 02/02/2010, 01:41
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 16 años
Puntos: 12
Respuesta: Listar informacion de un xml

lo intento con el siguiente codigo
Código PHP:
        $xml simplexml_load_string($buffer);
        
$players $xml->server->players;

        
print_r($players);

print
'        
<table width="431" border="0">
  <tr>
    <td width="228"><div align="center">Player Name</div></td>
    <td width="99">Player Score</td>
    <td width="90">Ping</td>
  </tr>'
;

foreach (
$players as $player){
    
    
$name     $player->player->name;
    
$score    $player->player->score;
    
$ping    $player->player->ping;

print
'
<tr>
    <td><div align="center">'
.$name.'</div></td>
    <td><div align="center">'
.$score.'</div></td>
    <td><div align="center">'
.$ping.'</div></td>
  </tr>'
;
}
print
'
</table>
'

pero solo me tira el primer registro, no saca los demas.

esta es la salida del print_r()
Cita:
SimpleXMLElement Object ( [player] => Array ( [0] => SimpleXMLElement Object ( [name] => fat1tyl.pl [score] => 2 [ping] => 217 ) [1] => SimpleXMLElement Object ( [name] => eeeeeeeeeeeeee [score] => 32 [ping] => 75 ) [2] => SimpleXMLElement Object ( [name] => Mr MC Clown [score] => 23 [ping] => 200 ) [3] => SimpleXMLElement Object ( [name] => *{PotW}*^3[U]B3R~ [score] => 49 [ping] => 95 ) [4] => SimpleXMLElement Object ( [name] => *{PotW}*spRonin [score] => 0 [ping] => 45 ) [5] => SimpleXMLElement Object ( [name] => BILL_CANT_RIDE [score] => 26 [ping] => 95 ) [6] => SimpleXMLElement Object ( [name] => chris1369aus [score] => 0 [ping] => 246 ) [7] => SimpleXMLElement Object ( [name] => Danger Prone [score] => 13 [ping] => 51 ) [8] => SimpleXMLElement Object ( [name] => a notion. [score] => 23 [ping] => 41 ) [9] => SimpleXMLElement Object ( [name] => =WD=SS-AUSSIE [score] => 5 [ping] => 201 ) [10] => SimpleXMLElement Object ( [name] => LinfoxJD [score] => 8 [ping] => 248 ) [11] => SimpleXMLElement Object ( [name] => TuFFeNuFF [score] => 15 [ping] => 207 ) [12] => SimpleXMLElement Object ( [name] => player whos wife gives bj when [score] => 8 [ping] => 32 ) [13] => SimpleXMLElement Object ( [name] => Kira [score] => 1 [ping] => 237 ) [14] => SimpleXMLElement Object ( [name] => TOG Mikey [score] => 5 [ping] => 298 ) [15] => SimpleXMLElement Object ( [name] => *{PotW}*NamVet [score] => 0 [ping] => 34 ) [16] => SimpleXMLElement Object ( [name] => {tr}frostbyte [score] => 0 [ping] => 81 ) [17] => SimpleXMLElement Object ( [name] => PowderMonkey [score] => 17 [ping] => 37 ) [18] => SimpleXMLElement Object ( [name] => Unknown Soldier [score] => 4 [ping] => 121 ) [19] => SimpleXMLElement Object ( [name] => PROWLER [score] => 12 [ping] => 32 ) [20] => SimpleXMLElement Object ( [name] => Hammil [score] => 31 [ping] => 48 ) ) )
  #5 (permalink)  
Antiguo 02/02/2010, 01:41
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Listar informacion de un xml

Edito: lo siento, es que pusiste otro post...

bueno, el punto es que debes iterar $players->player y no solo $players

analiza bien la estructura del objeto... ;)
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #6 (permalink)  
Antiguo 02/02/2010, 02:18
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 16 años
Puntos: 12
Respuesta: Listar informacion de un xml

vale te pasaste =)

Etiquetas: informacion, listar, xml
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:32.