Foros del Web » Programando para Internet » PHP »

simplexml_load_file()

Estas en el tema de simplexml_load_file() en el foro de PHP en Foros del Web. Hola Trato de parser from Ebay: Código PHP: $url = "http://svcs.ebay.com/MerchandisingService?OPERATION-NAME=getMostWatchedItems&SERVICE-NAME=MerchandisingService&SERVICE-VERSION=1.1.0&CONSUMER-ID=YOUR_API_ID&RESPONSE-DATA-FORMAT=XML&categoryId=397" ; $resp  =  simplexml_load_file ( $url ); print_r ( $resp );  Hast ahí todo ...
  #1 (permalink)  
Antiguo 27/08/2009, 16:17
(Desactivado)
 
Fecha de Ingreso: septiembre-2004
Mensajes: 360
Antigüedad: 19 años, 7 meses
Puntos: 1
simplexml_load_file()

Hola

Trato de parser from Ebay:

Código PHP:
$url="http://svcs.ebay.com/MerchandisingService?OPERATION-NAME=getMostWatchedItems&SERVICE-NAME=MerchandisingService&SERVICE-VERSION=1.1.0&CONSUMER-ID=YOUR_API_ID&RESPONSE-DATA-FORMAT=XML&categoryId=397";

$resp simplexml_load_file($url);

print_r($resp); 
Hast ahí todo bien, me devuelve este array:
Código PHP:
SimpleXMLElement Object
(
    [
ack] => Success
    
[version] => 1.1.0
    
[timestamp] => 2009-08-27T21:59:56.080Z
    
[itemRecommendations] => SimpleXMLElement Object
        
(
            [
item] => Array
                (
                    [
0] => SimpleXMLElement Object
                        
(
                            [
itemId] => 280388078141
                            
[title] => Vintage Atmos 2 LeCoultre Jaeger Mantel Clock 
                            
[viewItemURL] => http://cgi.ebay.com/Vintage-Atmos-2-LeCoultre-Jaeger-Mantel-Clock_W0QQitemZ280388078141QQcategoryZ13858QQcmdZViewItemQQ_trksidZm8QQ_trkparmsZalgo%3DMW%26its%3DC%26itu%3DUCC%26otn%3D8%26ps%3D50
                            
[currentPrice] => 500.0
                            
[globalId] => EBAY-US
                            
[timeLeft] => P4DT2H8M48S
                            
[subtitle] => EARLY CLOCK WITH LOW REGISTRATION NUMBER 1940s
                            
[country] => US
                            
[imageURL] => http://thumbs.ebaystatic.com/pict/280388078141_1.jpg
                            
[shippingType] => Freight
                        

Pero no logro acceder a cada elemento del array: itemid, title, etc.
Alguien tiene un minuto para decirme cómo.
Intento por ejemplo:

Código PHP:
$item $resp->item;   
$itemId $item->itemId;   
print 
$itemId
Pero nada... página en blanco
  #2 (permalink)  
Antiguo 27/08/2009, 16:32
 
Fecha de Ingreso: noviembre-2008
Mensajes: 8
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: simplexml_load_file()

Prueba de usar var_dump(), por ejemplo: var_dump(item);
cuentanos ! ;)
  #3 (permalink)  
Antiguo 27/08/2009, 16:49
(Desactivado)
 
Fecha de Ingreso: septiembre-2004
Mensajes: 360
Antigüedad: 19 años, 7 meses
Puntos: 1
Respuesta: simplexml_load_file()

Hago
var_dump(itemId);

Y obtengo:
string(6) "itemId"

  #4 (permalink)  
Antiguo 27/08/2009, 18:05
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: simplexml_load_file()

no seria que te falto el signo de $ en el var_dump
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #5 (permalink)  
Antiguo 27/08/2009, 23:05
(Desactivado)
 
Fecha de Ingreso: septiembre-2004
Mensajes: 360
Antigüedad: 19 años, 7 meses
Puntos: 1
Respuesta: simplexml_load_file()

nope
hago
var_dump($res);

me devuelve todo el contenido

cuando quiero acceder a un objeto intento
var_dump($itemID);

me devuelve NULL
  #6 (permalink)  
Antiguo 27/08/2009, 23:39
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: simplexml_load_file()

Cita:
Iniciado por Suyta Ver Mensaje
nope
hago
var_dump($res);

me devuelve todo el contenido

cuando quiero acceder a un objeto intento
var_dump($itemID);

me devuelve NULL
mmm... pues porque $itemID no existe tal cual...

debes usar la propiedad de $res
Código PHP:
var_dump($res->itemID); // por ejemplo 
pero no estoy seguro de que sea así... al menos, como lo haces no esta bien...

por favor, lee el manual al respecto...
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #7 (permalink)  
Antiguo 27/08/2009, 23:48
(Desactivado)
 
Fecha de Ingreso: septiembre-2004
Mensajes: 360
Antigüedad: 19 años, 7 meses
Puntos: 1
Respuesta: simplexml_load_file()

mmmmmmmmmmmmm no le entiendo al simplexml_load_file()
al menos con el formato que envía ebay.

Me resulta más fácil así:

Código PHP:
<?php

$url
="http://svcs.ebay.com/MerchandisingService?OPERATION-NAME=getMostWatchedItems&SERVICE-NAME=MerchandisingService&SERVICE-VERSION=1.1.0&CONSUMER-ID=YOUR_APPI_KEY&RESPONSE-DATA-FORMAT=XML&categoryId=397";


$str=file_get_contents($url);


if(
preg_match_all('/\<title\>([\w\W]*?)\<\/title\>/'$str$match)){
foreach(
$match[1] as $value
{   
        print 
$value."<br>";         
           
}   
}
?>
Gracias a todos !

Última edición por GatorV; 28/08/2009 a las 10:17
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 16:51.