DomDocument could not add link element for RSS feed

I am trying to create an RSS feed in PHP using DomDocument, but every time I try to make 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 am getting the following error.

XML parsing error: Inconsistent tag. Expected:. Location: http: //daddydonkey/feed.rss Line # 4, Column 58: This description ------------------------------ -------------------- ------- ^

0


a source to share


2 answers


I tried your PHP code and it works.



+1


a source


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



-1


a source







All Articles