2010-08-09 6 views
0

ici, je suis en train de créer un fichier xml dynamiquement lors de l'exécution, mais im obtenir erreur XML Parsing Error: indésirable après élément de document Lieu: http://localhost/tam/imagedata.php?imageid=8 ligne numéro 9, Colonne 1: ^XML Parsing Error

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

et le format xml est

<?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> 
+0

Pouvez-vous envoyer un échantillon du format de fichier XML – ChrisF

+0

Peut-être, vous pourriez nous donner la sortie XML? Cela aiderait plus que le code source PHP :) – brozo

+0

'$ id = (int) $ _GET ['imageid'];' – hsz

Répondre

0

Peut-être que vous publiez du code HTML dans le champ de description?

pourrait être utile d'ajouter un CDATASection au lieu d'un TextNode

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