Ver Mensaje Individual
  #18 (permalink)  
Antiguo 08/10/2011, 18:16
Avatar de andresdzphp
andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 9 meses
Puntos: 793
Respuesta: problema con api y xml no logro lo que busco

No hay problema, mira puedes usar también este ejemplo del manual

http://www.php.net/manual/en/book.simplexml.php#105998

me funcionó también.

Código PHP:
Ver original
  1. <?php
  2. class Obj2xml
  3. {
  4.     public $xmlResult;
  5.    
  6.     function __construct($rootNode) {
  7.         $this->xmlResult = new SimpleXMLElement("<$rootNode></$rootNode>");
  8.     }
  9.    
  10.     private function iteratechildren($object, $xml) {
  11.         foreach ($object as $name => $value) {
  12.             if (is_string($value) || is_numeric($value)) {
  13.                 $xml->$name = $value;
  14.             } else {
  15.                 $xml->$name = null;
  16.                 $this->iteratechildren($value, $xml->$name);
  17.             }
  18.         }
  19.     }
  20.    
  21.     function toXml($object) {
  22.         $this->iteratechildren($object, $this->xmlResult);
  23.         return $this->xmlResult->asXML();
  24.     }
  25. }
  26.  
  27. require ('xbox.php');
  28. $xbox = new XboxGamercard();
  29. $xbox->setGamertag('malatos');
  30. $xbox->setRegion('en-GB');
  31. $data = $xbox->fetchData();
  32.  
  33. $converter = new Obj2xml("API");
  34.  
  35. header("Content-Type:text/xml");
  36.  
  37. echo $converter->toXml($data);
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP

Última edición por andresdzphp; 08/10/2011 a las 18:23