2014-09-10 64 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

相关问题