Kane250 Posted June 26, 2009 Share Posted June 26, 2009 Hi, I'm fairly new to XML in general, and especially to creating it dynamically with PHP, but here goes my problem. I made a PHP script that generates a new XML document for a swf file I'm using when it is executed. On my own hosting it works fine. I have now moved it onto the hosting in which it is going to actually be used on, and I am getting the following error: "error on line 2 at column 1: Extra content at the end of the document". Can anyone take a look at this very lengthy code and see if something pops out that would be causing this? I thought perhaps their hosting was not running PHP 5, but it is, so i have no idea now. How can it work fine on one server and not work on another? <?php $amounttoshow = 25; $amounttoshow = $amounttoshow + 1; //Add 1 so our for loop will stop at the right place //Define paths $pathoptions = array("/", "/new"); //$randompath = "/"; //Create array of old job numbers $oldnumbers = file_get_contents('old.txt'); $oldnumbers = array_map('trim', explode(',', $oldnumbers)); //Create array of new job numbers $newnumbers = file_get_contents('new.txt'); $newnumbers = array_map('trim', explode(',', $newnumbers)); // create xml doctype $dom = new DOMDocument("1.0"); // display document in browser as plain text (for testing purposes!) //header("Content-Type: text/plain"); // display document in browser as xml (for actual use) header("Content-Type: text/xml"); // create root element $root = $dom->createElement("photos"); $dom->appendChild($root); // create photos path attribute $path = $dom->createAttribute("path"); $root->appendChild($path); // create photos path value $pathValue = $dom->createTextNode(""); $path->appendChild($pathValue); for($i=1; $i<$amounttoshow; $i++) { //Start the loop. // create photo child element $item = $dom->createElement("photo"); $root->appendChild($item); $randompath = $pathoptions[array_rand($pathoptions)]; if ($randompath == "/") { //If path is the old path, use array of old jobs, otherwise use the array of new jobs. $key = array_rand($oldnumbers); //Choose a random job $jobpath = $oldnumbers[$key]; $linkpath = $jobpath; //print "<b>link: </b>" . $linkpath . "<br />"; // create link attribute node $link = $dom->createAttribute("link"); $item->appendChild($link); // create link value node $linkValue = $dom->createTextNode($linkpath); $link->appendChild($linkValue); $thumbpath = "$linkpath/big.jpg"; //print "<b>thumbnail: </b>" . $thumbpath . "<br />"; // create attribute node $url = $dom->createAttribute("url"); $item->appendChild($url); // create photo url value node $urlValue = $dom->createTextNode($thumbpath); $url->appendChild($urlValue); $titlepath = $linkpath . "/title.txt"; //$title = file_get_contents($titlepath); $title = "test title"; //print "title is " . $title . "<br /><br />"; // create name attribute node $name = $dom->createAttribute("name"); $item->appendChild($name); // create mame value node $nameValue = $dom->createTextNode($title); $name->appendChild($nameValue); unset($oldnumbers[$key]); } elseif ($randompath == "/new") { $key = array_rand($newnumbers); //Choose a random job $linkpath = $newnumbers[$key]; $linkpath = "new/$linkpath"; //print "<b>link: </b>" . $linkpath . "<br />"; // create link attribute node $link = $dom->createAttribute("link"); $item->appendChild($link); // create link value node $linkValue = $dom->createTextNode($linkpath); $link->appendChild($linkValue); $thumbpath = "$linkpath/big.jpg"; //print "<b>thumbnail: </b>" . $thumbpath . "<br />"; $titlepath = $linkpath . "/title.txt"; // create attribute node $url = $dom->createAttribute("url"); $item->appendChild($url); // create photo url value node $urlValue = $dom->createTextNode($thumbpath); $url->appendChild($urlValue); //$title = file_get_contents($titlepath); $title = "test title"; //print "<b>title: </b>" . $titlepath . "<br /><br />"; //print "title is " . $title . "<br /><br />"; // create name attribute node $name = $dom->createAttribute("name"); $item->appendChild($name); // create mame value node $nameValue = $dom->createTextNode($title); $name->appendChild($nameValue); unset($newnumbers[$key]); } } // save and display tree on screen for testing //echo $dom->saveXML(); // save the xml file for use with PhotoFlow $dom->save("photoflow.xml"); ?> Quote Link to comment Share on other sites More sharing options...
natepizzle Posted June 26, 2009 Share Posted June 26, 2009 Can you attach old.txt and new.txt Quote Link to comment Share on other sites More sharing options...
Kane250 Posted June 26, 2009 Author Share Posted June 26, 2009 sure! They are just numbers I'm pulling into an array. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Kane250 Posted June 29, 2009 Author Share Posted June 29, 2009 Was anyone able to come up with anything by chance? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.