PHP 生成XML
我用这段代码生成xml
include("conn/conn.php");
$path = 'xml/createxml.xml';
if(file_exists($path)) unlink($path);
$handle = fopen($path, 'w') ;
$xmlContent .= '' ;
$xmlContent .= '
//查询所有板块
$select1 = $_POST['select1'] ;
$select2 =$_POST['select2'] ;
echo $select1 ;
echo $select2;
$query="select * from tb_car where car_road like '%$select1%' and car_road like '%$select2%'";
$result=mysql_query($query);
if(mysql_num_rows($result)>0){
while($myrow=mysql_fetch_array($result)){
$xmlContent .='
$xmlContent .='';
$xmlContent .='' ;
$xmlContent .='' ;
$xmlContent .='
}
}
$xmlContent .='
if($handle)
{
if(fwrite($handle, $xmlContent))
{
fclose($handle);
}
echo "<script> window.location.href='indexs.php?lmbs=车源信息查询&select1=$select1&select2=$select2';</script>";
}
?>
----
为什么生成后的xml data 和 value 的位置会调换
-
-
-
-
------解决方案--------------------
生成xml是这样的,你可以写dtd文件约束。
------解决方案--------------------
$xmlContent .='';
echo $xmlContent;exit();试试
------解决方案--------------------
<br /><?xml version="1.0" encoding="GB2312"?><br /><!DOCTYPE business [<br /> <!ELEMENT business (group)+><br /> <!ELEMENT group (data)+><br /> <!ELEMENT data ANY><br /> <!ATTLIST business comment CDATA #REQUIRED><br /> <!ATTLIST business id CDATA #REQUIRED><br /> <!ATTLIST data id ID #IMPLIED><br /> <!ATTLIST data name CDATA #REQUIRED><br /> <!ATTLIST data value CDATA #REQUIRED><br />]><br /><business><br />……<br /></business><br />