error on line 2 at column 1: Extra content at the end of the document
This page contains the following errors:
error on line 2 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
这是我封装的xml格式数据, 写的跟老师的一样, 一旦调用测试就报这个错误, 纠结中, 求助
源代码如下:
public static function xmlEncode($code,$message="",$data)
{
if(!is_numeric($code))
{
return "";
}
$result=array(
'code'=>$code,
'message'=>$messgae,
'data'=>$data
);
header("Content-Type:text/xml");
$xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
$xml .= "<root>";
$xml .= self::xmlToEncode($result);
$xml .= "</root>";
echo $xml;
}
public static function xmlToEncode($data)
{
$xml = "";
foreach ($data as $key => $value) {
$addr = "";
if(is_numeric($key)){
$addr = "id='{$key}'";
$key = 'item';
}
$xml .= "<{$key}{$addr}>";
$xml .= is_array($value) ? self::xmlToEncode($value) : $value;
$xml .= "</{$key}>\n";
}
return $xml;
}