使用PHP从数据库动态生成xml

时间:2018-11-22 15:08:12

标签: php mysql xml

我无法找出显示

的错误

'此页面包含以下错误: 第1行第2列的错误:StartTag:无效的元素名称 下面是直到第一个错误的页面呈现。'

init.php

<?php
$servername = "localhost";
$username = "root";
$password = null;
$databaseName = "test";

$db = mysqli_connect($servername, $username, 
$password, $databaseName)

?>

viewWishList.php

<?php                                            
header ("Content-Type:text/xml");
include ("config/init.php");
$query = "SELECT * FROM members"; 
$result = mysqli_query($connection, $query) or 
die ("Error in query: $query. ".mysql_error()); 

$_xml = '<?xml version="1.0"?>'                      
$_xml .="<wishList>"; 

while($row = mysqli_fetch_array($result)) { 

$_xml .="<wishlist>"; 

$_xml .="<wishlistID>".$row['wishlistID']." 
</wishlistID>"; 
$_xml .="<bookName>".$row['bookName']." 
</bookName>"; 
$_xml .="<bookType>".$row['bookType']." 
</bookType>"; 

 $_xml .="</wishlist>"; 

 } 

 $_xml .="</wishList>"; 

$xmlobj=new SimpleXMLElement($_xml);                                                                                         
print $xmlobj->asXML();                                          
$xmlobj->asXML(wishlist.xml);

 ?>

0 个答案:

没有答案