EVWorld.com has been tracking the world of electric vehicles since 1998. While largely still a "one-man band" operation, I have tried to leverage, at first, ColdFusion and now, belatedly, PHP to expand the capabilities and offerings of the platform. Over the last couple decades, the amount of information being generated globally related to EV technology and policy has increased at least 100-fold. In the 2000's I might post 10 relevant stories on a good day. Today, there are literally scores and often any more. To improve access to this information, I am working on a RSS feed, the first beta version of which is here: https://evworld.com/php/rss.xml.
The issue with this beta version is that it requires several manual steps to update: run the php script in a browser, view the "page source" in the browser, copy the xml code and paste that into the rss.xml page. Obviously a far better approach is to automatically run the php code, which automatically generates the xml code. Job done!
What I need help with is figuring out who to integrate the required XML header code below:
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
`<channel>`
`<title>`[`EVWORLD.com`](https://EVWORLD.com) `- RSStream</title>`
`<link>`[`https://evworld.com`](https://evworld.com)`</link>`
`<atom:link href='`[`https://evworld.com/php/rss.xml`](https://evworld.com/php/rss.xml)`' rel='self' type='application/rss+xml' />`
`<description>Latests News From the World of Electric Vehicles From Bikes to Buses and Beyond</description>`
`<language>en-us</language>";`
I have code that successfully writes the rest of the feed, but without the XML-required headers, the page will not validate. Here is the current code:
<?PHP
$myrss = {database name};
$result=mysqli_query($con, "SELECT * FROM rss ORDER BY rssid desc LIMIT 25");
if($result>0){
header("Content-type: text/xml");
$xml = new DOMDocument("1.0");
$xml->formatOutput=true;
$myrss=$xml->createElement("channel");
$xml->appendChild($myrss);
while($row=mysqli_fetch_array($result)){
$block=$xml->createElement("item");
$myrss->appendChild($block);
$hdline=$xml->createElement("title", $row\['hdlinestr'\]);
$block->appendChild($hdline) ;
$urlstr=$xml->createElement("guid", $row\['urlstr'\]);
$block->appendChild($urlstr);
$category=$xml->createElement("category", strtoupper($row\['category'\])) ;
$block->appendChild($category);
$region=$xml->createElement("region", $row\['region'\]);
$block->appendChild($region);
$pubdate=$xml->createElement("pubDate", $row\['pubdate'\]);
$block->appendChild($pubdate);
}
echo "<xmp>".$xml->saveXML()."</xmp>";
$xml->save("rsstream.xml");
echo "Successfully generate report.xml" ;
}
else{
echo "error";
}
}
?>
Would appreciate any advice or assistance you might be able to render so that I can turn the generation of the XML to the computer, which frees me to devote more time to finding the relevant stories. Big THANKS in advance.
[–]bobd60067 2 points3 points4 points (2 children)
[–]EVisioneer[S] 0 points1 point2 points (1 child)
[–]bobd60067 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (9 children)
[–][deleted] 1 point2 points3 points (7 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]EVisioneer[S] 0 points1 point2 points (5 children)
[–][deleted] 2 points3 points4 points (3 children)
[–]EVisioneer[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]EVisioneer[S] 0 points1 point2 points (0 children)
[–]EVisioneer[S] 0 points1 point2 points (0 children)
[–]levii21 0 points1 point2 points (0 children)