tags:

views:

43

answers:

1

hi every one . here i am creating xml file dynamically at run time but i m getting error XML Parsing Error: junk after document element Location: http://localhost/tam/imagedata.php?imageid=8 Line Number 9, Column 1: ^

   $id=$_GET['imageid'];
     $dom = new DomDocument('1.0'); 
     $query="select * from tbl_image_gallery where imageId='$id'";
    $select=mysql_query($query);
    while($res=mysql_fetch_array($select))
    {
        $content = $dom->appendChild($dom->createElement('content')); 
        $image = $content->appendChild($dom->createElement('image')); 
        $small_image_path = $image->appendChild($dom->createElement('small_image_path'));
        $small_image_path->appendChild($dom->createTextNode("load/images/small/".$res['image']));  
        $big_image_path = $image->appendChild($dom->createElement('big_image_path'));
        $big_image_path->appendChild($dom->createTextNode("load/images/big/".$res['image'])); 
        $description = $image->appendChild($dom->createElement('description'));
        $description->appendChild($dom->createTextNode($res['description']));  
        $dom->formatOutput = true;
     }   
    echo $test1 = $dom->saveXML(); 

and xml format is

<?xml version="1.0"?>
<content>
  <image>
    <small_image_path>load/images/small/1.jpg</small_image_path>
    <big_image_path>load/images/big/1.jpg</big_image_path>
    <description>hgjghj</description>
  </image>
<image><small_image_path>load/images/small/2.jpg</small_image_path><big_image_path>load/images/big/2.jpg</big_image_path><description>fgsdfg</description></image><image><small_image_path>load/images/small/3.jpg</small_image_path><big_image_path>load/images/big/3.jpg</big_image_path><description>sdfgsdfg</description></image><image><small_image_path>load/images/small/4.jpg</small_image_path><big_image_path>load/images/big/4.jpg</big_image_path><description>gsbhsg</description></image><image><small_image_path>load/images/small/4.jpg</small_image_path><big_image_path>load/images/big/4.jpg</big_image_path><description>gsbhsg</description></image><image><small_image_path>load/images/small/avatar.jpg</small_image_path><big_image_path>load/images/big/avatar.jpg</big_image_path><description></description></image></content>
A: 

Can it be that you are posting html code into the description field?

Could be usefull to add a CDataSection instead of a TextNode

$cdata = $dom->createCDATASection($res['description']);
$image->appendChild($cdata);