【问题标题】:XML Parsing Error: not well-formed in FFXML 解析错误:在 FF 中格式不正确
【发布时间】:2014-11-03 19:25:59
【问题描述】:

我有以下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

请帮我解决这个问题。

【问题讨论】:

标签: php xml .htaccess


【解决方案1】:

首先检查响应文档的来源(大多数浏览器中的ctrl+u或cmd+u)。确保 PHP 已执行且未传递到浏览器。

您在header('Content-type: application/xml'); 调用之前输出内容。 &lt;?php ..?&gt; 之外的任何内容都是浏览器的输出。在您的情况下,xml 声明。

如果您的数据库处理停止脚本,您将没有输出。这里没有我能看到的错误处理。

您可能会收到一条错误消息。使用浏览器的开发人员工具查看响应和/或检查响应源。

XML 作为文本生成。添加数据库中的值而不进行转义。使用htmlspecialchars() 转义特殊字符,如&lt;&amp;。最好使用 XMLWriter 或 DOM 来生成 XML 并让它们处理转义。

【讨论】:

  • 你能解释一下吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多