Foros del Web » Programando para Internet » PHP »

Me pueden ayudar con php y xml

Estas en el tema de Me pueden ayudar con php y xml en el foro de PHP en Foros del Web. Hola me pueden ayudar con php y xml para mi es nuevo esto de xml y php necesito mostrar los atributos de un archivo xml ...
  #1 (permalink)  
Antiguo 26/07/2009, 21:46
 
Fecha de Ingreso: abril-2009
Mensajes: 14
Antigüedad: 15 años
Puntos: 0
Me pueden ayudar con php y xml

Hola

me pueden ayudar con php y xml

para mi es nuevo esto de xml y php necesito mostrar los atributos de un archivo xml
este es el archivo xml:
noticias.xml
Código PHP:
<libreria>
<
casio ins="Del" sht="avpag" title="Kist"/>
</
libreria>] 
Mostrar.php
Código PHP:
$file="noticias.xml";
$data =  file_get_contents($file); 
$xml simplexml_load_string($data);

// ejemplo
foreach ($xml->casio as $casios){
echo 
"Author: ".$casios->ins."<br />";
echo 
"Title: ".$casios->sht."<br />";
echo 
"Publisher: ".$casios->title."<br />";
echo 
"<hr />";

El problema es que no me muestra nada que da en blanco.
Gracias de antemano
  #2 (permalink)  
Antiguo 26/07/2009, 23:25
 
Fecha de Ingreso: abril-2009
Mensajes: 14
Antigüedad: 15 años
Puntos: 0
Respuesta: Me pueden ayudar con php y xml

Al fin me salio. Yo creo que le puede servir a alguien

Archivosphp

prueva.php
Código PHP:
<?php

   
// Carga una cadena XML desde un archivo...  
  
$xmlstr file_get_contents'noticas.xml' );  
  
$library = new SimpleXMLElement$xmlstr );  
    
  
// Carga un archivo XML  
  
$library = new SimpleXMLElement('noticas.xml'nulltrue);  


   echo 
'<table>';  
  echo 
'<tr>';  
  echo 
'<th>Title</th><th>Author</th> 
         <th>Publisher</th><th>ISBN</th>'
;  
  echo 
'</tr>';  
  foreach( 
$library->book as $book ) {  
     echo 
'<tr>';  
      echo 
'<td>' $book->title '</td>';  
      echo 
'<td>' $book->author '</td>';  
      echo 
'<td>' $book->publisher '</td>';  
      echo 
'<td>' $book['isbn'] . '</td>'
      echo 
'<td>' $book->song '</td>'
      echo 
'</tr>';  
   }  
   echo 
'</table>';  


   echo 
'<table>';  
  echo 
'<tr>';  
  echo 
'<th>Title</th><th>Author</th> 
         <th>Publisher</th><th>ISBN</th>'
;  
  echo 
'</tr>';  
  foreach( 
$library->songs as $songs ) {  
     echo 
'<tr>';  
      echo 
'<td>' $songs->title '</td>';  
      echo 
'<td>' $songs->author '</td>';  
      echo 
'<td>' $songs->publisher '</td>';  
      echo 
'<td>' $songs['isbn'] . '</td>'
      echo 
'<td>' $songs->song '</td>'
      echo 
'</tr>';  
   }  
   echo 
'</table>';

Novede.xml

Código PHP:
 <library>  
     <
book isbn="0345342968">  
        <
title>Fahrenheit 451</title>  
         <
author>RBradbury</author>  
         <
publisher>Del Rey</publisher>  
         
     </
book>  

     <
songs isbn="0345342968">  
        <
title>Fahrenheit 451</title>  
         <
author>RBradbury</author>  
         <
publisher>Del Rey</publisher>  
         <
song>Luis Sagastume</song>
     </
songs
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 05:24.