views:

177

answers:

2

I am trying to create an RSS feed in PHP using DomDocument but every time I try to make a node like http://domain.com the script fails

$oDomDocument = new DOMDocument( "1.0", "iso-8859-1" );

// Create the root now
$oRootNode = $oDomDocument->createElement( "rss" );
$oRootNode->setAttribute( "version", "2.0" );
$oDomDocument->appendChild( $oRootNode );

// Create the channel node
$oChannelNode = $oDomDocument->createElement( "channel" );
$oRootNode->appendChild( $oChannelNode );

// Add site details
$oChannelNode->appendChild( $oDomDocument->createElement( "title", "Site Title" ) );
$oChannelNode->appendChild( $oDomDocument->createElement( "link", "http://google.com" ) );
$oChannelNode->appendChild( $oDomDocument->createElement( "description", "This is a description" ) );
$oChannelNode->appendChild( $oDomDocument->createElement( "language", "en-us" ) );

I get the following error..

XML Parsing Error: mismatched tag. Expected: . Location: http://daddydonkey/feed.rss Line Number 4, Column 58:This is a description ---------------------------------------------------------^

A: 

Your code sample, as written, runs and produces valid XML without an error like the one you provided. Perhaps your sample got truncated when you pasted it?

Jonathan Campbell
+1  A: 

I tried your PHP code and it works.

Christian Toma