XML text problem
Posted: Wed Feb 21, 2007 1:41 pm
I am trying to generate a rss feed and i use feed from nytimes. the feed has a got a few characters such as â that makes the xml document invalid. i do not know to clean it. i though if i create a text DOM element, it would automatically alter to make it valid but it did not do it. how to fix this?
my code
Any help is deeply appreciated.
Code: Select all
<item>
<title>Lisbon Journal: A Song Form Is Updated, but Not in the Alleys of Its Originhttp://www.nytimes.com/2007/02/21/world/europe/21portugal.html?ex=1329714000&en=09de80043e8dc8cc&ei=5088&partner=rssnyt&emc=rss</title>
<link>http://www.nytimes.com/2007/02/21/world/europe/21portugal.html?ex=1329714000</link>
<description>The traditional music known as fado, which means fate, has been reinvented to become Portugalâ</description>
</item>Code: Select all
foreach ($rssPostList as $feed) {
//create item
$item = $doc->createElement( "item" );
$title = $doc->createElement( "title" );
$title->appendChild( $doc->createTextNode( trim( $feed->get('title') ) ) );
$link = $doc->createElement( "link", trim( $feed->get('link') ) );
$title->appendChild( $doc->createTextNode( trim( $feed->get('link') ) ) );
$desription = $doc->createElement( "description", trim( $feed->get('description') ) );
$title->appendChild( $doc->createTextNode( trim( $feed->get('description') ) ) );
//append title, link, description, language, publishedDate to channel
$item->appendChild( $title );
$item->appendChild( $link );
$item->appendChild( $desription );
$itemList->appendChild( $item );
}