note 109584 modified in domdocument.savexml by danbrown

From: 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.&#13;&#10;By Richard Holm, Sweden.&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;$domdoc=new DOMDocument();&#13;&#10;$domdoc-&#62;load(&#39;articles.xml&#39;);&#13;&#10;$xmldoc=$domdoc-&#62;saveXML();&#13;&#10;&#13;&#10;echo &#34;Using htmlentities()&#60;br/&#62;&#34;;&#13;&#10;echo &#39;&#60;b style=&#34;font-family:monospace&#34;&#62;&#39;.htmlentities($xmldoc).&#39;&#60;/b&#62;&#39;;&#13;&#10;&#13;&#10;echo &#34;&#60;br/&#62;&#60;br/&#62;Using strtr()&#60;br/&#62;&#34;;&#13;&#10;$tr=array(&#39;&#60;&#39;=&#62;&#39;&#60;&#39;,&#39;&#62;&#39;=&#62;&#39;&#62;&#39;,&#39; &#39;=&#62;&#39; &#39;,&#34;\\n&#34;=&#62;&#39;&#60;br/&#62;&#39;);&#13;&#10;echo &#39;&#60;b style=&#34;font-family:monospace&#34;&#62;&#39;.strtr($xmldoc,$tr).&#39;&#60;/b&#62;&#39;;&#13;&#10;&#13;&#10;echo &#34;&#60;br/&#62;&#60;br/&#62;Using xmp-tag&#34;;&#13;&#10;echo &#39;&#60;b style=&#34;font-family:monospace&#34;&#62;&#60;xmp&#62;&#39;.$xmldoc.&#39;&#60;/xmp&#62;&#60;/b&#62;&#39;;&#13;&#10;?&#62;&#13;&#10;&#13;&#10;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('<'=>'&lt;','>'=>'&gt;',' '=>'&nbsp;',"\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

« previous php.notes (#190030) next »