XML响应
问题描述:
编辑
如何在XML “头” 加编码XML响应
现在的 “头” 是这样的:
<?xml version="1.0"?>
你怎么能使用SimpleXML时在PHP中添加一个编码在“标题”?
我的XML类:
class XML {
private $root = '<response />';
function __construct($root=null){
$this->root = new SimpleXMLElement($root ? $root:$this->root);
}
function encode($arr, $node=null){
$node = $node == null ? $this->root:$node;
foreach($arr as $key => $value){
if(is_array($value)){
$this->encode($value, $node->addChild($key));
}
else{
$node->addChild($key, $value);
}
}
}
function output(){
return $this->root->asXML();
}
}
答
那么我丹麦是不完美的(或目前在所有为此事)。但是,我知道XML节点cannot begin with a number。由于错误似乎是抱怨XML数据的格式良好,我想说这是因为<0></0>
节点。
你可以尝试改变:
private $root = '<response />';
为了这样的事情:
private $root = '<?xml version="1.0" encoding="utf-8" ?><response />';
什么是错误您收到? – jerluc
在我的问题看看 – clarkk