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格式數(shù)據(jù), ?寫的跟老師的一樣, ?一旦調(diào)用測試就報(bào)這個(gè)錯(cuò)誤, ?糾結(jié)中, ?求助
源代碼如下:
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;
}