rgutierrez1014 Posted December 18, 2009 Share Posted December 18, 2009 Hi everyone, I have a script that reads data from a database and outputs it in an XML (supposedly) so that it can be an RSS feed. It reads the data and puts it in an array just fine, it's just that when I go to create a new DOMDocument, it seems to break the script. Here's my code, without the array $post, which I know works (hopefully it's not overwhelming): // Create XML object $doc = new DOMDocument("1.0", "utf-8"); $doc->load("write.xml"); $doc->formatOutput = true; // Creates root rss element $root = $doc->createElement( "rss" ); $attrib = $doc->setAttribute( "version", "2.0" ); $root->appendChild( $attrib ); $doc->appendChild( $root ); // Create channel $channel = $doc->createElement( "channel" ); // Create channel info $chtitle = $doc->createElement( "title" ); $chtitle->appendChild( $doc->createTextNode("RCE News and Updates") ); $channel->appendChild( $chtitle ); $chlink = $doc->createElement( "link" ); $chlink->appendChild( $doc->createTextNode( "http://rce.csuchico.edu/news/" ) ); $channel->appendChild( $chlink ); $chlanguage = $doc->createElement( "language" ); $chlanguage->appendChild( $doc->createTextNode( "en-us" ) ); $channel->appendChild( $chlanguage ); $chcopyright = $doc->createElement( "copyright" ); $chcopyright->appendChild( $doc->createTextNode( "Copyright 2009" ) ); $channel->appendChild( $chcopyright ); $chdocs = $doc->createElement( "docs" ); $chdocs->appendChild( $doc->createTextNode( "http://blogs.law.harvard.edu/tech/rss" ) ); $channel->appendChild( $chdocs ); // Populates elements foreach( $post as $i ) { // Creates parent node $item = $doc->createElement( "item" ); // Creates Node $title = $doc->createElement( "title" ); $title->appendChild( $doc->createTextNode( $i['title'] ) ); // Attaches Node to parent $item->appendChild( $title ); // Creates New Node $description = $doc->createElement( "description" ); $description->appendChild( $doc->createTextNode( $i['description'] ) ); // Attaches Node to Parent $item->appendChild( $description ); // Creates New Node $link = $doc->createElement( "link" ); $link->appendChild( $doc->createTextNode( $i['link'] ) ); // Attaches Node to Parent $item->appendChild( $link ); // Creates New Node $guid = $doc->createElement( "guid" ); $guid->appendChild( $doc->createTextNode( $i['guid'] ) ); // Attaches Node to Parent $item->appendChild( $guid ); // Creates New Node $category = $doc->createElement( "category" ); $category->appendChild( $doc->createTextNode( $i['category'] ) ); // Attaches Node to Parent $item->appendChild( $category ); // Creates New Node $pubdate = $doc->createElement( "pubdate" ); $pubdate->appendChild( $doc->createTextNode( $i['pubdate'] ) ); // Attaches Node to Parent $item->appendChild( $pubdate ); // Attaches Parent to Channel $channel->appendChild( $item ); } // Attach Channel to Root $root->appendChild($channel); mysql_close($mdl_db); // Writes XML echo $doc->saveXML(); $doc->save("write.xml"); Is there somewhere else that it's breaking? I would appreciate any help! Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/185654-script-seems-to-break-at-domdocument/ Share on other sites More sharing options...
abazoskib Posted December 19, 2009 Share Posted December 19, 2009 This should be the top of your script: // Create XML object $doc = new DOMDocument("1.0", "utf-8"); $doc->load("write.xml"); $doc->formatOutput = true; // Creates root rss element $root = $doc->createElement( "rss" ); $attrib = $doc->createElement( "attrib" ); $root->appendChild( $attrib ); $attrib->setAttribute( "version", "2.0" ); $doc->appendChild( $root ); // Create channel $channel = $doc->createElement( "channel" ); Other than that, its hard to tell without looking at $post, and write.xml Link to comment https://forums.phpfreaks.com/topic/185654-script-seems-to-break-at-domdocument/#findComment-980348 Share on other sites More sharing options...
rgutierrez1014 Posted January 4, 2010 Author Share Posted January 4, 2010 Alright, thanks! I'll give that a try Link to comment https://forums.phpfreaks.com/topic/185654-script-seems-to-break-at-domdocument/#findComment-988218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.