我在try 阅读和解析此提要时遇到了问题: 一些XML提要
由于某些原因,函数SimpleXMLElement返回空 node .我使用FILE_GET_CONTENTS读取URL,然后使用SimpleXMLElement.
下面是一个例子:
<?php
// URL feed XML
$url = 'some xml feed';
$xml_content = file_get_contents($url);
if ($xml_content === false) {
echo "No XML content.";
exit;
}
// Parser the XML
$xml = new SimpleXMLElement($xml_content);
foreach ($xml->channel->item as $item) {
$title = (string) $item->title;
$id = (string) $item->{'cnn-article:id'};
$description = (string) $item->description;
// Hacer lo que necesites con los datos
echo "Title: $title<br>";
echo "ID: $id<br>";
echo "Description: $description<br>";
}
?>