我试图在HTML中显示原始XML。如果没有HTML元素的XML显示细腻但是一旦添加我的内容,我给出的这个错误在HTML中显示XML
error on line 37 at column 6: XML declaration allowed only at the start of the document
做一些研究之后,这个问题是很常见的,有白色的空间,但我不能发现任何。下面是我的源代码问题。
<?php require 'header.php'; ?>
<div class="sixteen columns">
<h3>XML</h3>
<?php
header("Content-Type:text/xml");//Tell browser to expect xml
include("config/init.php");
$connection = mysqli_connect($hostname, $username, $password, $databaseName) or die("you did not connect");
$query = "SELECT * FROM art";
$result = mysqli_query($connection, $query) or die (mysqli_error($connection));
//Top of xml file
$_xml = '<?xml version="1.0" encoding="UTF-8"?>';
$_xml .="<art>";
while($row = mysqli_fetch_array($result)) {
$_xml .="<art>";
$_xml .="<art_name>".$row['name']."</art_name>";
$_xml .="<art_category>".$row['category']."</art_category>";
$_xml .="<art_price>".$row['price']."</art_price>";
$_xml .="</art>";
}
$_xml .="</art>";
//Parse and create an xml object using the string
$xmlobj=new SimpleXMLElement($_xml);
print $xmlobj->asXML();
$xmlobj->asXML('art.xml');
?>
</div>
<?php require 'footer.php'; ?>
http://www.acalvert.x10host.com/xml.php如果你想查看页面源
您不能在HTML文档中更改内容类型。您是否尝试显示* XML标记*或尝试使用XML标记,以便以某种方式呈现XML元素?究竟如何? XML元素没有默认的格式(除了CSS意义上的内联元素)。 – 2014-12-04 23:25:15
试图显示XML标记,以便它显示在我的页面中。 I.E我可以查看页眉,页脚等 – Calv 2014-12-04 23:37:15