2014-09-10 74 views
0

我有以下XML文件:XML解析錯誤:沒有很好地形成,在FF

<?xml version="1.0" encoding="UTF-8"?> 
<?php 
    header('Content-type: application/xml'); 
    require_once('includes/pdo_connection.php'); 
    $query = "Select * from photo_category WHERE status='A'"; 
    $result = DB::instance()->prepare($query)->execute()->fetchAll(); 
    $output="<juiceboxgallery galleryTitle='FutureFit Gallery'>"; 
    foreach($result as $row) { 
    $cat_id = $row['id']; 
    $cat_name = $row['photo_category_name']; 
    $query2 = "Select * from photogallery WHERE pcID = '$cat_id' AND status = 'A' order by id desc"; 
    $result2 = DB::instance()->prepare($query2)->execute()->fetchAll(); 
    foreach($result2 as $row2) { 
     $imgCaption = $row2['img_label']; 
     $thumb = $row2['thumb_img']; 
     $large = $row2['photo_gallery_image']; 
     $output .= "<image imageURL='images/photogallery/large/$large' 
      thumbURL='images/photogallery/thumb/$thumb' 
      linkURL='' 
      linkTarget='_blank'> 
      <title>".$imgCaption."</title> 
     </image>"; 
    } 
    } 
    $output .= "</juiceboxgallery>"; ?> 
<?php echo $output; ?> 

而在.htaccess我使用如下:

<IfModule mod_php5.c> 
    <FilesMatch "\.xml$"> 
    SetHandler application/x-httpd-php 
    </FilesMatch> 
</IfModule> 

現在,當我運行這個XML我服務器我得到錯誤,XML格式不正確。錯誤是如下:

XML Parsing Error: not well-formed 
$output= '<juiceboxgallery galleryTitle="FutureFit Gallery">'; 

而在Chrome瀏覽器中的錯誤說:

error on line 6 at column 50: Document is empty 

請幫我解決這個問題。

+0

看看這個[thread] [1]我想你會從那裏找到你的解決方案。 [1]:http://stackoverflow.com/questions/4075742/regex-to-strip-html-tags – 2014-09-10 08:24:50

回答

0

首先檢查響應文檔的來源(在大多數瀏覽器中按Ctrl + u或cmd + u)。確保PHP已執行並且未傳送到瀏覽器。

您輸出header('Content-type: application/xml');調用之前的內容。 <?php ..?>以外的任何內容都是瀏覽器的輸出。在你的情況下,XML聲明。

如果您的數據庫處理停止腳本,您將無法輸出。這裏沒有我能看到的錯誤處理。

您可能會收到一條錯誤消息。使用瀏覽器的開發人員工具查看響應和/或檢查響應源。

XML以文本形式生成。數據庫中的值在不轉義的情況下添加。使用htmlspecialchars()可以轉義特殊字符,如<&。更好的使用XMLWriter或DOM來生成XML並讓他們處理轉義。

+0

u能請解釋更多關於這個? – 2014-09-11 19:54:39

相關問題