Buenas comunidad, tengo una duda, he creado una vista xml desde un archivo con extensión .php, pero me gustaría saber si, ¿Puedo replicar lo que he hecho pero desde un archivo .xml?. Muchas gracias de antemano.
<?php
$html = "";
$url = "https://sports.yahoo.com/soccer/mls/rss.xml?shangrila=1";
$xml = simplexml_load_file($url);
header("content-type: text/xml");
echo('<?xml version="1.0" encoding="UTF-8" ?>');
// $html .= ' <rss version="2.0">'; // si descomentas se verá como un rss
$html .= ' <channel>';
foreach ($xml->channel as $object) {
$html .=' <title> '.$object->title.' </title>'; // cabecera
$html .=' <description> '.$object->description.' </description>';
}
for($i=0; $i<10;$i++){ // cantidad de noticias
$title = $object->item[$i]->title;
$link = $object->item[$i]->link;
$description = $object->item[$i]->description;
$pubDate = $object->item[$i]->pubDate;
$guid = $object->item[$i]->guid;
$html .='<item>';
$html .=' <title> '.$title.' </title>';
$html .=' <link> '.$link.' </link>';
$html .=' <description>'.$description.' </description>';
$html .=' <pubDate> '.$pubDate.' </pubDate>';
$html .=' <guid> '.$guid.' </guid>';
$html.='</item>';
}
$html .= " </channel>";
// $html .= " </rss>";
//
echo $html;
file_put_contents("rss.xml",$html);
?>
PD: si quieren ver el código que he creado me hacen saber y lo coloco.