hitech Posted March 7, 2008 Share Posted March 7, 2008 I am using cURL to get RSS files and then Javascript parse the file. If I save the file and then read with Javascript, works fine, like this: $ch = curl_init('http://news.google.com/news?ned=us&topic=h&output=rss'); $fp = fopen("nvrss.xml", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); <script> var rssDoc = new ActiveXObject("Microsoft.XMLDOM"); rssDoc.async = false; rssDoc.load('nvrss.xml'); itemNodes = rssDoc.selectNodes("/rss/channel/item"); </script> But, if I pass variable directly from cURL to Javascript, works only if the RSS file does not have CDATA in title or description. $ch = curl_init("http://g1.globo.com/Rss2/0,,AS0-5597,00.xml"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); //$txt = curl_exec($ch); $txt = str_replace("\"","'",$txt); $txt = str_replace("\n"," ",$txt); curl_close($ch); <script> var rssDoc = new ActiveXObject("Microsoft.XMLDOM"); rssDoc.async = false; rssDoc.loadXML("<?=$txt;?>"); itemNodes = rssDoc.selectNodes("/rss/channel/item"); </script> Why when I pass RSS via variable directly from cURL, Javascript can´t read file that contain CDATA? Thanks Helcio Brazil Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.