1
我生成一些XML数据以响应HTTP POST请求。我正在设置MIMEPHP - 格式化XML输出
header('Content-type: text/xml');
到目前为止一切正常。
我生成XML响应如下:
$response = '<?xml version="1.0" encoding="utf-8"?>';
$response .= '<error>';
$response .= '<description>'.$error.'</description>';
$response .= '</error>';
echo $response;
我现在想格式的XML,这样也看不到这样的响应:
<?xml version="1.0" encoding="utf-8"?><error><description>Login Error: No Username Supplied</description></error>
他们看到这样的响应:
<?xml version="1.0" encoding="utf-8"?>
<error>
<description>Login Error: No Username Supplied</description>
</error>
我还没有与PHP的XML输出工作,所以不知道是否有内置在输出中执行“漂亮打印”类型函数的方法?
你是如何输出XML?看看这个线程,http://stackoverflow.com/questions/8615422/php-xml-how-to-output-nice-format。 – chris85
稍有偏离:“正确地格式化XML” - 两种版本都不如其他版本更正确。你可能意思是“更易读的”。然后文档定义必须允许(即可以跳过空格)。 – VolkerK