[英]XML Parsing Error: not well-formed in FF
我有下面的XML
文件:
<?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
請幫助我解決此問題。
首先檢查響應文檔的來源(大多數瀏覽器中為ctrl + u或cmd + u)。 確保已執行PHP,並且未將其交付給瀏覽器。
您在header('Content-type: application/xml');
之前輸出內容header('Content-type: application/xml');
呼叫。 <?php ..?>
以外的任何內容都是瀏覽器的輸出。 您的情況是xml聲明。
如果您的數據庫處理停止了腳本,那么您將沒有輸出。 我看不到這里有任何錯誤處理。
您可能會收到一條錯誤消息。 使用瀏覽器的開發人員工具查看響應和/或檢查響應源。
XML作為文本生成。 來自數據庫的值被添加而沒有轉義。 使用htmlspecialchars()
轉義特殊字符,例如<
或&
。 甚至最好使用XMLWriter或DOM來生成XML,並讓他們處理轉義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.