i have xml file( product.xml) and i need to display the whole content( including xml declaration , tags and node values) of this file within php program. how can i achieve that?
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">
<开发者_如何学Gotype>cosmetic</type>
<address>
<suburb>Melbourne</suburb>
</address>
</product>
</products>
output:
<?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>
<?php echo htmlspecialchars(file_get_contents('product.xml')); ?>
The question is a bit misleading. Properly formalized: How can I display the raw XML in a browser using PHP.
精彩评论