Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/07/2011, 10:55
igonfil
 
Fecha de Ingreso: junio-2008
Mensajes: 250
Antigüedad: 15 años, 10 meses
Puntos: 1
Mostrar el id del nodo

¿Cómo puedo mostrar el valor del id del nodo direccion de xml con php?
El xml es el siguiente:

Cita:
<?xml version="1.0" encoding="iso-8859-1"?>
<date>

<mapa >
<!--para que los caracteres no den error utilizamos <![CDATA[Contenido]]> -->
<titulo><![CDATA[Título1]]> </titulo>
<direccion id="1">


</direccion>

</mapa>

<mapa >
<!--para que los caracteres no den error utilizamos <![CDATA[Contenido]]> -->
<titulo></titulo>
<direccion id="2">
Hola
</direccion>
</mapa>

</date>

El código PHP es:
Código PHP:
<?php

//$library = simplexml_load_file( 'xml/Referencias.xml' );
//$ruta_fichero="http://www.dominio.com/noticias.xml"; 
function CargarXML($ruta_fichero

$contenido ""
if(
$da fopen($ruta_fichero,"r" )) 

while (
$auxfgets($da,1024)) 

$contenido.=$aux

fclose($da); 

else 

echo 
"Error: no se ha podido leer el archivo <strong>$ruta_fichero</strong>"

//Remplazar caracteres
$contenido=ereg_replace("á","&aacute;",$contenido); 
$contenido=ereg_replace("é","&eacute;",$contenido); 
$contenido=ereg_replace("í","&iacute;",$contenido); 
$contenido=ereg_replace("ó","&oacute;",$contenido); 
$contenido=ereg_replace("ú","&uacute;",$contenido); 
$contenido=ereg_replace("Á","&Aacute;",$contenido); 
$contenido=ereg_replace("É","&Eacute;",$contenido); 
$contenido=ereg_replace("Í","&Iacute;",$contenido); 
$contenido=ereg_replace("Ó","&Oacute;",$contenido); 
$contenido=ereg_replace("Ú","&Uacute;",$contenido); 
$contenido=ereg_replace("Ñ","&Ntilde;",$contenido); 
$contenido=ereg_replace("ñ","&ntilde;",$contenido);
$contenido=ereg_replace("º","",$contenido);  

$tagnames = array ("direccion""titulo" ); 

if (!
$xml domxml_open_mem($contenido)) 

echo 
"Ha ocurrido un error al procesar el documento<strong> \"$ruta_fichero\"</strong> a XML <br>"
exit; 

else 

$raiz $xml->document_element(); 

$tam=sizeof($tagnames); 

for(
$i=0$i<$tam$i++) 

$nodo $raiz->get_elements_by_tagname($tagnames[$i]); 
$j=0
foreach (
$nodo as $etiqueta

$matriz[$j][$tagnames[$i]]=$etiqueta->get_content(); 
$j++; 



return 
$matriz


$matriz=CargarXML("xml/Mapas.xml" ); 

$num_noticias=sizeof($matriz); 
for(
$i=0;$i<$num_noticias;$i++) 

echo 

<font face="Calibri" size="2" color="#000000"><b>'
.$matriz[$i]["direccion"].'</b><br>
</font>'


 




?>