note 109584 modified in domdocument.savexml by danbrown
| From: | danbrown@php.net | Date: | Fri, 10 Aug 2012 16:25:46 +0000 |
| Subject: | note 109584 modified in domdocument.savexml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190030@lists.php.net to get a copy of this message | ||
There are no best way to display the complete contens in an xml file in general (tags included).
Here are three ways for you to try out. By Richard Holm,
Sweden. <?php $domdoc=new
DOMDocument(); $domdoc->load('articles.xml'); $xmldoc=$domdoc->saveXML(); echo
"Using htmlentities()<br/>"; echo
'<b
style="font-family:monospace">'.htmlentities($xmldoc).'</b>'; echo
"<br/><br/>Using
strtr()<br/>"; $tr=array('<'=>'<','>'=>'>','
'=>'Â ',"\\n"=>'<br/>'); echo
'<b
style="font-family:monospace">'.strtr($xmldoc,$tr).'</b>'; echo
"<br/><br/>Using xmp-tag"; echo
'<b
style="font-family:monospace"><xmp>'.$xmldoc.'</xmp></b>'; ?> Note:
xmp-tag is deprecated (no support). However, some browsers still support it. My favorites are:
Mozilla, Chrome and none Microsoft products.
--was--
There are no best way to display the complete contens in an xml file in general (tags included).
Here are three ways for you to try out. Which one do you prefere?
By Richard Holm, Sweden.
<?php
$domdoc=new DOMDocument();
$domdoc->load('articles.xml');
$xmldoc=$domdoc->saveXML();
echo "Using htmlentities()<br/>";
echo '<b
style="font-family:monospace">'.htmlentities($xmldoc).'</b>';
echo "<br/><br/>Using strtr()<br/>";
$tr=array('<'=>'<','>'=>'>','
'=>' ',"\n"=>'<br/>');
echo '<b
style="font-family:monospace">'.strtr($xmldoc,$tr).'</b>';
echo "<br/><br/>Using xmp-tag";
echo '<b
style="font-family:monospace"><xmp>'.$xmldoc.'</xmp></b>';
?>
Note: xmp-tag is deprecated (no support). However, some browsers still support it. My favorites are:
Mozilla, Chrome and none Microsoft products.
http://php.net/manual/en/domdocument.savexml.php