Foros del Web » Programando para Internet » PHP »

Error al extraer datos desde XML

Estas en el tema de Error al extraer datos desde XML en el foro de PHP en Foros del Web. Buenas a todos Tengo un problema al extraer y querer mostrar los datos de un archivo XML situado en un servidor remoto, estoy creando la ...
  #1 (permalink)  
Antiguo 17/04/2016, 20:06
 
Fecha de Ingreso: abril-2005
Mensajes: 2
Antigüedad: 19 años
Puntos: 0
Pregunta Error al extraer datos desde XML

Buenas a todos

Tengo un problema al extraer y querer mostrar los datos de un archivo XML situado en un servidor remoto, estoy creando la web en local con XAMPP 5.6.8 y Wordpress.

Tengo creado este código para extraer la información;

Código PHP:
<?php
header
("Content-type: text/html; charset=utf-8");
$xml file_get_contents("https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&stationString=LEMD");
$DOM = new DOMDocument('1.0''utf-8');
$DOM->loadXML($xml);
$raw $DOM->getElementsByTagName('raw_text')
?>
Y este otro para mostrar la información en pantalla;

Código PHP:
<?php
foreach ($raw as $raw) {
    echo  
'<li>' .utf8_decode($raw->getElementsByTagName("raw_text")->item(0)->nodeValue).' </li>';
}
?>
Todo esta en un archivo HTML quedando así (archivo de prueba);

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
header("Content-type: text/html; charset=utf-8");
$xml = file_get_contents("https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&stationString=LEMD");
$DOM = new DOMDocument('1.0', 'utf-8');
$DOM->loadXML($xml);
$raw = $DOM->getElementsByTagName('raw_text')
?>

<ul>

<?php
foreach ($raw as $raw) {
	echo  '<li>' .utf8_decode($raw->getElementsByTagName("raw_text")->item(0)->nodeValue).' </li>';
}
?>

</body>
</html> 
El enlace del archivo XML es este;

https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&f ormat=xml&hoursBeforeNow=3&mostRecent=true&station String=LEMD

Bueno pues al cargarlo donde debería ir lo que se muestra en el apartado de la web es esto;

loadXML($xml); $raw = $DOM->getElementsByTagName('raw_text') ?>
' .utf8_decode($raw->getElementsByTagName("raw_text")->item(0)->nodeValue).' '; } ?>

No se si el problema esta en la parte del código o si directamente XAMPP no permite la carga de archivos en servidores externos, espero que alguien pueda ayudarme.

Un saludo a todos

Etiquetas: html, xml
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 19:03.