Problem with loading remote XML file

mayham

New Member
I'm trying to load a remote xml file using php.This is my code:\[code\]$doc = new DOMDocument();$doc->load($this->xml_file);$file = $doc->getElementsByTagName('file');$totalFiles = $file->length;echo $totalFiles;\[/code\]The remote xml file link is:\[code\]http://localhost/script/index.php?act=xml\[/code\]This is the code in \[code\]index.php\[/code\]:\[code\]$xml = '<?xml version="1.0"?><MultimediaGallery>';$query = mysql_query('SELECT `id`,`image`,`desc` FROM `' .confitem('database','prefix').'table` ORDER BY `id` DESC LIMIT ' .$start.','.$limit);while($result = mysql_fetch_array($query)){ $img = unserialize($result['image']); $desc = unserialize($result['desc']); $xml .= '<file type="photo"><thumb>' .settings('site','url').'/'.OPATH_APPFOLDER.'/' .OPATH_UPFOLDER.'/wallpapers/thumbs/'.$img[0].'</thumb><source>' .settings('site','url') .'/'.OPATH_APPFOLDER.'/'.OPATH_UPFOLDER .'/wallpapers/'.$img[0].'</source><description>' .$desc[$_SESSION['languagecode']].'</description></file>';}$xml .= '</MultimediaGallery>';header("content-type: text/xml");echo $xml;\[/code\]When I visit this xml file link direct in the browser .. it's output to me xml file with this style :\[code\]<?xml version="1.0"?><MultimediaGallery><file type="photo"><thumb>http://localhost/script/application/data/wallpapers/thumbs/1116205566_42ce0841ab_s.jpg</thumb><source>http://localhost/script/application/data/wallpapers/1116205566_42ce0841ab_s.jpg</source><description>dfdfdfdf</description></file></MultimediaGallery>\[/code\]When I execute the xml function which uses the dom to load the xml file I get this error:\[quote\] Warning: DOMDocument::load() [domdocument.load]: Extra content at the end of the document in http://localhost/script/index.php, line: 2 in C:\AppServ\www\script\application\libraries\wallpapers\multimedia.class.php on line 46\[/quote\]Why is this happening?Update:I used dom to create the xml instead:\[code\]$xml = new DOMDocument('1.0');$root = $xml->createElement('MultimediaGallery');$xml->appendChild($root); $query = mysql_query('SELECT `id`,`image`,`desc` FROM `'.confitem('database','prefix').'backgrounds` ORDER BY `id` DESC LIMIT '.$start.','.$limit);while($result = mysql_fetch_array($query)) { $img = unserialize($result['image']); $desc = unserialize($result['desc']); $element = $xml->createElement('file'); $root->appendChild($element); $attr = $xml->createAttribute('type'); $element->appendChild($attr); $attr_text = $xml->createTextNode('photo'); $attr->appendChild($attr_text); $thumb = $xml->createElement('thumb'); $element->appendChild($thumb); $thumb_text = $xml->createTextNode(settings('site','url').'/'.OPATH_APPFOLDER.'/'.OPATH_UPFOLDER.'/wallpapers/thumbs/'.$img[0]); $thumb->appendChild($thumb_text); $source = $xml->createElement('source'); $element->appendChild($source); $source_text = $xml->createTextNode(settings('site','url').'/'.OPATH_APPFOLDER.'/'.OPATH_UPFOLDER.'/wallpapers/'.$img[0]); $source->appendChild($source_text); $description = $xml->createElement('description'); $element->appendChild($description); $description_text = $xml->createTextNode($desc[$_SESSION['languagecode']]); $description->appendChild($description_text); }header("content-type: text/xml");echo $xml->saveXML();\[/code\]But it still gives me the same error. I noticed some thing though, I tried to copy my output xml and save it in a file and read it using the dom parser and the result was that it's read successfully.But when I try parsing the xml output by the php file then it throws an error.
 
Back
Top