XML报错
XML 声明非良好格式怎么解决啊
XML 声明非良好格式怎么解决啊
2014-12-24
public static function xml($code,$message='',$data=array())
{
if(!is_numeric($code))
{
return '';
}
$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data,
);
header("Content-Type:text/xml");
$xml="<?xml version '1.0' encoding='utf-8'?>";
$xml.="<root>";
$xml.=self::Toxml($data);
$xml.="</root>";
echo $xml;
/* $xml.="<root>\n";
$xml.="<code>200</code>\n";
$xml.="<message>数据返回成功</message>\n";
$xml.="<data>\n";
$xml.="<id>1</id>\n";
$xml.="<name>lisi</name>\n";
$xml.="</data>\n";
$xml.="</root>";
echo $xml;*/
}
public static function Toxml($data)
{
$xml="";
foreach($data as $k=>$v)
{
$xml.= "<{$k}>";
$xml.=$v;
$xml.="</{$k}>";
}
return $xml;
}
}
/*$data=array(
'id'=>1,
'name'=>'zhangsan',
);
Respondse::xml(200,'success',$data);
报XML 声明非良好格式
举报