Foros del Web » Programando para Internet » PHP »

Leer un XML con php y SimpleXML

Estas en el tema de Leer un XML con php y SimpleXML en el foro de PHP en Foros del Web. El documento XML vendria asi: Código: <catalog> − <product> <id> 48 </id> <title> Boltrona Single Seater - Leather </title> − <description> texto desription </description> <price> ...
  #1 (permalink)  
Antiguo 06/09/2009, 10:24
Avatar de GXT2  
Fecha de Ingreso: junio-2009
Ubicación: Fort Lauderdale, FL
Mensajes: 152
Antigüedad: 14 años, 11 meses
Puntos: 0
Leer un XML con php y SimpleXML

El documento XML vendria asi:

Código:
<catalog><product>
<id>48</id>
<title>Boltrona Single Seater - Leather</title><description>
texto desription 
</description>
<price> 1185  </price><thumbimg>
www .kmpfurniture.com/admin/uploads/BoltronasingleseaterleatherThumbnail.jpg
</thumbimg>

<collection>Fire</collection>
<category>leather sofas fabric sofas</category>

</product>
</catalog> 


La interpretacion con php y simpleXML .. ojo el codigo corre sobre php5

Código PHP:

<center>
<?php
$xml 
simplexml_load_file("kmpfurniture   .com  /  feeds/kmpfurniture_catalog2 . xml"); ?>
<table border="0" >
<tr>
<td colspan="5" align="center" style="font-size:50px; color:#993300; font-family:Arial;" >
JUST FIRE
</td>
</tr>
<tr>
<td colspan="5" align="left">Share this page: <a href="facebook.com/share.php?u=olympus-tours.com/kmpfurniture_catalog .    php"><img src="esp .kmpfurniture.com/Ads/images/win-cancun-trip_15.  jpg" alt="Facebook" width="24" height="25" border="0"></a> <br />
KMP Furniture store is committed to exceed your expectations of quality and good service, with a variety of Contemporary and Modern Furniture.
</td>
</tr>
 <tr>
    <?
    $cont
=0;
    foreach(
$xml->product as $product)
      { 
//foreach ?>
        <?
        
if ($cont == 0//Este es un break para hacer el salto en la tabla cada 5 productos
        
{echo "<tr>";} // imprimo un tr cuando el $con del producto es multiplo de 5
        //if($cont==(string)$product->collection == "Fire"){ echo"<tr>" }
        
if((string)$product->collection == "Fire"// pregunto si ese producto es de  la coleccion Fire
         
//ifB ?>
   <td align="center" style="padding:3px 3px 3px 3px" valign="top">
          <table border="0" cellpadding="0" cellspacing="0" width="180px" style="border:1px solid #666666">
           <tr>
            <th  height="44px" valign="middle" align="center" style="padding:0 2px 0px 2px;">
              <?
               printf
("%s\n"$product->title); 
              
?>
            </th>
           </tr>
           <tr>
           <th> 
              <?   
               
echo "<img src='"
               
printf($product->thumbimg); 
               echo 
"' width='170px' height='139px'/>" 
              
?>
           </th>
           </tr>
           <tr>
           <th>   
               <form target="paypal" action="paypal.com/cgi-bin/webscr" method="post">
               <input type="hidden" name="cmd" value="_cart">
               <input type="hidden" name="business" value="66UQTPVMTW3D4">
               <input type="hidden" name="lc" value="US">
              
                <input type="hidden" name="item_name" value='<? printf("%s\n"$product->title);?>'> 
                <input type="hidden" name="item_number" value='<? printf("%s\n"$product->id);?>'>
                <input type="hidden" name="amount" value=' <? printf("%s\n"$product->price);?>'>
                 
                <input type="hidden" name="currency_code" value="USD">
                <input type="hidden" name="button_subtype" value="products">
                <input type="hidden" name="add" value="1">
                <input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_SM.gif:NonHosted">
                <input type="image" src="paypal.com/en_US/i/btn/btn_cart_SM.gif" 
                 border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
                 <img alt="" border="0" src="paypal.com/es_XC/i/scr/pixel.gif" width="1" height="1">
                </form>
             </th>
             <tr>
             <th>   
                <?
                printf
("Price: $ %s\n "$product->price);
                
?> 
             </th>
             <tr>
             <!--<th>    
                <?
                
/*printf("Collection:  %s\n ", $product->collection);*/  //imprime una celda mas y la coleccion
                
$cont $cont+1;
                
?>
            </th>-->
             </tr>
              </table>  
          <?
            
}//ifB
             
?>
   </td>
    <?    
     
//foreach ?>
   </tr>
    </table>
</center>
Ver el resultado del codigo aqui:
Código:
NuevosMillonariosEnInternet.com/kmpfurniture_catalog.php
  #2 (permalink)  
Antiguo 06/09/2009, 10:49
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Leer un XML con php y SimpleXML

que tipo de mensaje es este??

una aportación??
o una duda (porque no la veo)??

sea lo que sea, es bueno que siempre se coloque la información necesaria... no sea que se confunda al usuario mas de lo que parece!!
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 06/09/2009, 11:43
Avatar de GXT2  
Fecha de Ingreso: junio-2009
Ubicación: Fort Lauderdale, FL
Mensajes: 152
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Leer un XML con php y SimpleXML

Es una aportacion Amigos...
  #4 (permalink)  
Antiguo 06/09/2009, 13:25
 
Fecha de Ingreso: enero-2009
Mensajes: 40
Antigüedad: 15 años, 3 meses
Puntos: 1
Respuesta: Leer un XML con php y SimpleXML

Gracias GXT2 creo que dentro lo utilizare
  #5 (permalink)  
Antiguo 25/10/2009, 08:42
Avatar de GERMANCIN  
Fecha de Ingreso: junio-2004
Mensajes: 151
Antigüedad: 19 años, 10 meses
Puntos: 0
Respuesta: Leer un XML con php y SimpleXML

Es justo lo que buscaba mil gracias...

Cita:
Iniciado por GXT2 Ver Mensaje
Es una aportacion Amigos...
__________________
Ineternet Business
  #6 (permalink)  
Antiguo 26/10/2009, 13:52
Avatar de jpunk  
Fecha de Ingreso: octubre-2005
Ubicación: Bogota
Mensajes: 335
Antigüedad: 18 años, 7 meses
Puntos: 0
Respuesta: Leer un XML con php y SimpleXML

buen aporte en estos dìas necesito estudiar sobre esto justamente

gracias.
  #7 (permalink)  
Antiguo 26/10/2009, 13:55
Avatar de GXT2  
Fecha de Ingreso: junio-2009
Ubicación: Fort Lauderdale, FL
Mensajes: 152
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Leer un XML con php y SimpleXML

Cita:
Iniciado por jpunk Ver Mensaje
buen aporte en estos dìas necesito estudiar sobre esto justamente

gracias.
De nada disfrutalo y si tienes alguna pregunta posteala por aqui para seguir la conversacion paz
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 04:42.