0
我有xml文件(product.xml),我需要在php程序中顯示此文件的全部內容(包括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>
51個答案之後,你應該知道你需要將代碼縮進4個空格...... P – deceze 2011-05-10 02:12:40
@deceze實際上,當我使用單行代碼結束反引號時, :P – Mel 2011-05-10 02:14:28
它只顯示節點值,但不顯示xml decelaration和tags.i表示格式與存儲在「product.xml」文件中相同 – sara 2011-05-10 02:20:46