2010-08-09 154 views
0

我在這裏創建動態XML文件在運行時間,但即時得到錯誤 XML解析錯誤:文檔元素後的垃圾 地點:http://localhost/tam/imagedata.php?imageid=8 行號9,第1列: ^XML解析錯誤

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

和xml格式是

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

你能後的XML文件格式 – ChrisF 2010-08-09 11:20:20

+0

的樣本或許,你可以給我們的XML輸出?這將有助於超過PHP源代碼:) – brozo 2010-08-09 11:20:32

+0

'$ id =(int)$ _GET ['imageid'];' – hsz 2010-08-09 11:21:48

回答

0

是否可以將您的HTML代碼發佈到說明字段?

可能是有用的添加的CDATASection代替TextNode

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