I need help from an expert, please.
My project is this: I take XML feeds from two sources and run them through MagicParser to turn them into RSS Feeds.
the new RSS feeds are then sent to another script that turns each RSS item into content and stores it in the program I am using Joomla.
Everything seems to be working fine except for the illegal characters that keep appearing in the XML feed. The error that I keep getting most of the time is "A semi colon character was expected." From what I can find on the web this is a result of illegal characters.
1. Can someone please take a quick look at my code below and let me know if I wrote it correctly.
2. Can someone please tell me what I need add to the code below to stop this error or strip out the illegal characters.
Any help will be deeply appreciated,
David
<?php
require("MagicParser.php");
function myRecordHandler($video)
{
print "<item>";
print "<author>Search Video</author>";
print "<title>".$video["TITLE"]."</title>";
print "<link>".$video["VIDEOURL"]."</link>";
print "<description>";
print "<![CDATA[";
print "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
print "<tr>";
print "<td rowspan=\"6\" valign=\"top\"><img src='".$video["THUMBNAILURL"]."' border=\"0\" width=\"120\" height=\"90\"></td><td rowspan=\"6\"> </td></tr>";
print "<tr><td>";
print "<b>Runtime:</b> ".$video["RUNTIME"]." seconds";
print "</td></tr>";
print "<tr><td>";
print "".$video["DESCRIPTION"]." ";
print "</td></tr>";
print "<tr><td>";
print "<b>Category:</b> ".$video["CATEGORY"]." - <b>Channel:</b> ".$video["CHANNEL"]."";
print "</td></tr>";
print "<tr><td>";
print "<b>Tags:</b> ".$video["TAGS"]." ";
print "</td></tr></table>";
print "]]>";
print "</description>";
print "</item>";
}
print "< ?xml version=\"1.0\" encoding=\"utf-8\" ? >";
print "<rss version= \"2.0\" xmlns:media=\"http://search.yahoo.com/mrss/\">";
print "<channel>";
print "<title>Search Video</title>";
print "<h1>Search Video</h1>";
print "<link></link>";
print "<image>";
print "<url>http://video.google.es/common/logo_video.jpg</url>";
print "<link>http://www.searchvideo.com</link>";
print "<title>Search Video</title>";
print "<height>63</height>";
print "<width>123</width>";
print "</image>";
print "<description>Videos</description>";
MagicParser_parse("http://beta.searchvideo.com/apiv3?appid=1x1jhj64466mi12ia&method=truveo.videos.getVideos&query=category:\"News\"%20sort:mostRecent&results=20","myRecordHandler","xml|RESPONSE/VIDEOSET/VIDEO/");
print "</channel>";
print "</rss>";
?>
Yes, here is an example url: http://www.vids411.com/parser/searchvideo17.php. I paste this directly into IE7 and I get the error. I can paste the same link into my RSS Reader in Joomla and it will import some of the links but not all. Any ideas?
Hi David,
To make it easier to debug, could you add the following PHP code to the very first line of your script:
header("Content-Type: text/xml");
Thanks,
David.
Sorry for being so dumb put I am not doing something right when I put the line of code in it gives errors.
Can you please give an example of where I put the line of code?
Sorry, David - It's a PHP statement, so it needs to go after your opening PHP tag.
...for example:
<?php
header("Content-Type: text/xml");
... rest of script ...
?>
This will make sure that all browsers interpret the output as XML.
Thanks,
David.
Do you mean like this
<?php
header("Content-Type: text/xml");
require("MagicParser.php");
Hi David,
The problem is being caused by this line:
print "<link>".$video["VIDEOURL"]."</link>";
VIDEOURL contains the & character, which needs to be entity encoded when included within an XML document.
The easiest thing to do is to use the htmlentities() function, which makes non-CDATA content "XML safe", for example:
print "<link>".htmlentities($video["VIDEOURL"])."</link>";
That should do the trick!
Hope this helps,
Cheers,
David.
David,
Thank you very much it appears to be working fine.
Again thanks a million,
David
Hi David,
I am getting the same issue in my xml file saying, a semi colon was expected. My xml format is a bit different from yours and I have that $ character at multiple places in the xml. Can you please tell me where can I put the method suggested by you in the xml file to make it working.
Here is the file sample
http://www.healthology.com/Xml/XmlGenerator/XmlGenerator.aspx?brand_name=healthatoz&src=2&style=12
<?xml version="1.0" encoding="utf-8" ?>
<Videos copyright="Copyright Healthology, Inc., an iVillage Company providing health education">
<Video>
<VideoDuration>00:06:30</VideoDuration>
<ContentID>1926</ContentID>
<FocusGroup>
<FocusArea>diabetes</FocusArea>
<FocusArea>diabetes-treatment</FocusArea>
<FocusArea>heart-health</FocusArea>
<FocusArea>hypertension-treatment</FocusArea>
<FocusArea>stroke</FocusArea>
</FocusGroup>
<ShortTitle>Treating Diabetic Hypertension</ShortTitle>
<FullTitle>Hypertension and Diabetes: Treatment Goals</FullTitle>
<Authors>
<Author title="" first="Mabel" middle="" last="Jong" />
<Author title="MD" first="Domenic" middle="" last="Sica" />
<Author title="MD, FACP" first="William" middle="B." last="White" />
</Authors>
<Img100x80>http://www.healthology.com/img_lib/10045.jpg</Img100x80>
<Img40x60>http://www.healthology.com/img_lib/10045_b.jpg</Img40x60>
<Summary>
<![CDATA[ It's long been known that diabetes often goes hand-in-hand with high blood pressure. But many of the 11 million Americans that have both conditions don't get the treatment they need. Join experts as they discuss why people with diabetes also need to focus on controlling their blood pressure.
]]>
</Summary>
<Keywords>hypertension, high blood pressure, diabetes, kidney disease, heart attack, heart failure, stroke, vascular disease, insulin, blood sugar, blood pressure, atherosclerosis, obesity, high cholesterol, smoking, coronary artery disease, congestive heart failure, peripheral vascular disease, end-stage renal disease, chronic renal failure, treatment, blood pressure medications, exercise, diet, blood sugar medicine, normal blood pressure levels, blood glucose levels</Keywords>
<PubDate>2007-12-18T15:12:00</PubDate>
<ReviewDate>2002-09-17T00:00:00</ReviewDate>
<VideoLaunchCode>
<a onclick="javascript:window.open(this.href,'VideoPlayer','scrollbars=no,resizable=no,width=732,height=604,status=no');return false;" href="http://healthatoz.healthology.com/hybrid/hybrid-autodetect.aspx?content_id=1926&focus_handle=diabetes&brand_name=healthatoz" target="_blank">Treating Diabetic Hypertension</a>
</VideoLaunchCode>
</Video>
<Video>
<VideoDuration>00:06:05</VideoDuration>
<ContentID>2700</ContentID>
<FocusGroup>
<FocusArea>depression</FocusArea>
<FocusArea>depression-information</FocusArea>
<FocusArea>mental-health-information</FocusArea>
</FocusGroup>
<ShortTitle>Seasonal Depression</ShortTitle>
<FullTitle>Shedding Light on Seasonal Depression</FullTitle>
<Authors>
<Author title="PhD" first="Michael" middle="" last="Terman" />
<Author title="MD" first="Gabrielle" middle="" last="Morris" />
</Authors>
<Img100x80>http://www.healthology.com/img_lib/101591.jpg</Img100x80>
<Img40x60>http://www.healthology.com/img_lib/101591_b.jpg</Img40x60>
<Summary>
<![CDATA[ Every winter, when the days get shorter, people with seasonal affective disorder, also known as SAD, experience depression. Learn how light can help chase away the winter blues.
]]>
</Summary>
<Keywords>Seasonal affective disorder, S.A.D, SAD, winter blues, holiday blues, Winter SAD, Light therapy, light box therapy, psychotherapy, cognitive therapy, dawn simulation, negative air ionization, melatonin, serotonin, antidepressants, sunlight, depression, winter depression, fatigue, oversleep, increased sleep, hypersomnia, sleep, irritability, anxiety, increased appetite, low energy, mood changes, suicidal thoughts, weight gain, difficulty concentrating, social withdrawal, decreased sex drive, Personal Inventory for Depression and SAD,</Keywords>
<PubDate>2007-12-03T16:54:00</PubDate>
<ReviewDate>2006-05-19T00:00:00</ReviewDate>
<VideoLaunchCode>
<a onclick="javascript:window.open(this.href,'VideoPlayer','scrollbars=no,resizable=no,width=732,height=604,status=no');return false;" href=htmlentities("http://healthatoz.healthology.com/hybrid/hybrid-autodetect.aspx?content_id=2700&focus_handle=depression&brand_name=healthatoz)" target="_blank">Seasonal Depression</a>
</VideoLaunchCode>
</Video>
<Video>
<VideoDuration>00:03:55</VideoDuration>
<ContentID>4069</ContentID>
<FocusGroup>
<FocusArea>skin-cancer-prevention</FocusArea>
</FocusGroup>
<ShortTitle>Sunscreen 101</ShortTitle>
<FullTitle>Sunscreen 101</FullTitle>
<Authors>
<Author title="MD" first="Betty" middle="" last="Bellman" />
<Author title="" first="Susan" middle="" last="Cingari" />
<Author title="MD" first="Barry" middle="" last="Resnik" />
<Author title="MD" first="Kimberly" middle="" last="Bazar" />
</Authors>
<Img100x80>http://www.healthology.com/img_lib/101554.jpg</Img100x80>
<Img40x60>http://www.healthology.com/img_lib/101554_b.jpg</Img40x60>
<Summary>
<![CDATA[ In the past, a tan was considered a sign of health. But today we know more about the harmful effects of sun exposure, from wrinkling to skin cancer and with this new understanding have come developments in the way we protect our skin. Join our panel of experts for a discussion of the latest in suncare.
]]>
</Summary>
<Keywords>Sun care, wrinkles, skin cancer, zinc oxide, sunblock, sunscreens, micronized titanium dioxide, PABA, UVA, UVB, tanning salon, sun damage, American Academy of Dermatology, self-tanning lotions, bronzing lotions, SPF, Dr. Betty Bellman, Dr. Barry Resnik</Keywords>
<PubDate>2007-11-08T11:20:00</PubDate>
<ReviewDate>2006-04-11T00:00:00</ReviewDate>
<VideoLaunchCode>
<a onclick="javascript:window.open(this.href,'VideoPlayer','scrollbars=no,resizable=no,width=732,height=604,status=no');return false;" href="http://healthatoz.healthology.com/hybrid/hybrid-autodetect.aspx?content_id=4069&focus_handle=skin-cancer-prevention&brand_name=healthatoz" target="_blank">Sunscreen 101</a>
</VideoLaunchCode>
</Video>
</Videos>
Thanks in Advance
Vipin
Hello Vipin,
The VideoLaunchCode element could certainly cause problems without being CDATA delimited as it contains HTML code, which is very similar to XML and could easily break the formatting. To fix this, simply add CDATA tags just as you have with the Summary element, for example:
<VideoLaunchCode>
<![CDATA[
<a onclick="javascript:window.open(this.href,'VideoPlayer','scrollbars=no,resizable=no,width=732,height=604,status=no');return false;" href="http://healthatoz.healthology.com/hybrid/hybrid-autodetect.aspx?content_id=4069&focus_handle=skin-cancer-prevention&brand_name=healthatoz" target="_blank">Sunscreen 101</a>
]]>
</VideoLaunchCode>
Hope this helps,
Cheers,
David.
Hi David,
When you are you getting the "A semi colon character was expected."?
Is it being produced by the browser when it tries to display the output XML from your script?
Cheers,
David.