我有xml文件(product.xml),我需要在php程序中显示该文件的全部内容(包括xml声明,标签和节点值)。我怎么能实现这个目标?
products.xml
<?xml version="1.0" encoding="utf-8"?>
<products>
<product onshelf="yes">
<type>cosmetic</type>
<address>
<suburb>Melbourne</suburb>
</address>
</product>
<product onshelf="yes">
<type>cosmetic</type>
<address>
<suburb>Melbourne</suburb>
</address>
</product>
</products>
输出:
<?xml version="1.0" encoding="utf-8"?>
<products>
<product onshelf="yes">
<type>cosmetic</type>
<address>
<suburb>Melbourne</suburb>
</address>
</product>
<product onshelf="yes">
<type>cosmetic</type>
<address>
<suburb>Melbourne</suburb>
</address>
</product>
</products>
答案 0 :(得分:1)
<?php echo htmlspecialchars(file_get_contents('product.xml')); ?>
这个问题有点误导。正式形式化: 如何使用PHP在浏览器中显示原始XML。