【发布时间】:2020-01-24 14:35:34
【问题描述】:
我需要通过 Apache 请求在浏览器中显示一个 XML 文件。所以我可以将文件提供给freeswitch。我的 PHP 代码是这样的:
<?php
header('Content-Type: text/xml');
$xml=simplexml_load_file("test.xml") or die("not found");
echo "<pre>".print_r($xml,true)."</pre>";
?>
但是我得到了这个输出:
<pre>SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => freeswitch/xml
)
[section] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => configuration
)
[configuration] => SimpleXMLElement Object
(
[@attributes] => Array
(
[description] => Network Lists
[name] => acl.conf
)
[network-lists] => SimpleXMLElement Object
(
[list] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => localhost_allow
[default] => allow
)
[node] => SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => allow
[cidr] => 127.0.0.1/32
)
)
</pre>
我只需要在浏览器中输出漂亮的 xml。或者我可以以另一种方式提供 xml 文件。任何想法? 谢谢
【问题讨论】:
标签: php xml pretty-print