什么php函数可以从XML文件中显示格式化的XHTML?

什么php函数可以从XML文件中显示格式化的XHTML?

问题描述:

Ive been trying to display formatted content blocks from a xml file with no luck. Ive been using simplexml_load_file and other varients which Im now seeing cannot deal with the xhtml tags within the called tag ... eg.

//php contents
 <?php $xml=simplexml_load_file("file.xml");
 echo ($xml->entry); ?>

//xml contents
 <entry>
 <p>This does not work</p>
 </entry>

whereas

 <entry>This works</entry>

can someone please tell me which php function can do this from an xml file and or what is the best way to display the contents with xhtml formatting?

Im trying to dynamically load content to a webpage without having to build too many pages. I like the idea of having all my content in one xml file for easy edits.

Theres not enough content to justify a database yet.

Thanks in advance

我一直试图从xml文件中显示格式化的内容块而没有运气。 我一直在使用simplexml_load_file和其他我现在看到的变量无法处理被调用标签中的xhtml标签...例如。 p>

  // php contents 
&lt;?php  $ xml = simplexml_load_file(“file.xml”); 
 echo($ xml-&gt; entry);  ?&gt; 
  code>  pre> 
 
 
  // xml contents 
&lt; entry&gt; 
&lt; p&gt;这不起作用&lt  ; / p&gt; 
&lt; / entry&gt; 
  code>  pre> 
 
 

而 p>

 &lt; entry&gt;这适用于&lt;  / entry&gt; 
  code>  pre> 
 
 

有人可以告诉我哪个php函数可以从xml文件中执行此操作,或者 是什么是使用xhtml格式显示内容的最佳方式 ? p>

我试图动态地将内容加载到网页而不必构建太多页面。 我喜欢将所有内容放在一个xml文件中以便于编辑的想法。 p>

Theres还没有足够的内容来证明数据库的合理性。 p>

谢谢 提前 p> div>

You can try dumping the contents of a certain simplexml node (in this case: $xml->entry) using the asXml function.

echo $xml->entry->asXml();

Check the php documentation on simplexml here (link to the asXml() call):

Simplexml documentation

im getting closer... I found asXML() which outputs the html tags... but not sure yet how to point to specific blocks.... eg $xml->asXML(block) displays 1

got it

$xml->block->asXML() 

works

would still like to know if there is a better method tho.