tags:

views:

29

answers:

3

hello .. i'm trying to load remote xml file using php .. this is the function :

    $doc = new DOMDocument();
    $doc->load($this->xml_file);
    $file = $doc->getElementsByTagName('file');
    $totalFiles = $file->length;

    echo $totalFiles;

and the remote xml file link is : http://localhost/script/index.php?act=xml

which this link generate xml output .. this is it's php 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;

so when i visit this xml file link direct in the browser .. it's output to me xml file with this style :

<?xml version="1.0"?><MultimediaGallery><file type="photo"><thumb>http://localhost/script/application/data/wallpapers/thumbs/1116205566_42ce0841ab_s.jpg&lt;/thumb&gt;&lt;source&gt;http://localhost/script/application/data/wallpapers/1116205566_42ce0841ab_s.jpg&lt;/source&gt;&lt;description&gt;dfdfdfdf&lt;/description&gt;&lt;/file&gt;&lt;/MultimediaGallery&gt;

but when i visit the xml function which use dom to load the xml file , it's output this error message :

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

so please tell me actually what is the problem and what are steps to solve it ..

thanks alto ..

A: 

Your XML is not well-formed. E.g there is something wrong with it.

Try to avoid making XML by concatenating strings because this will happen. You can use DomDocument you make XML as well as read it and manipulate it.

Make sure you have no leading or trailing white space in your XML generating script.

You should also be using CDATA

jakenoble
A: 

hello

thanx alot .. so i used dom to create the xml :

    $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();

but it's still give me tha same error .. i noticed some thing .. i tried to copy my output xml and save it in xml file and read it by the dom parser .. so the result was that it's readed it successfully !!! .. but when try parsing the xml output by the php file then it's gave me this error .. so plz any idea ??

Jason4Ever
A: 

hello ,

ok i solved my problem by using for parsing the xml file the function $xml->loadXML() instead of $xml->load()

thx :)

Jason4Ever