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

时间:2022-08-26 23:23:24

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.

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

//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?

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

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.

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

Theres not enough content to justify a database yet.

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

Thanks in advance

提前致谢

2 个解决方案

#1


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

您可以尝试使用asXml函数转储某个simplexml节点的内容(在本例中为$ xml-> entry)。

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

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

在这里查看simplexml上的php文档(链接到asXml()调用):

Simplexml documentation

#2


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

我越来越近了......我发现asXML()输出了html标签......但还不确定如何指向特定的块....例如$ xml-> asXML(block)显示1

got it

$xml->block->asXML() 

works

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

我还是想知道是否有更好的方法。

#1


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

您可以尝试使用asXml函数转储某个simplexml节点的内容(在本例中为$ xml-> entry)。

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

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

在这里查看simplexml上的php文档(链接到asXml()调用):

Simplexml documentation

#2


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

我越来越近了......我发现asXML()输出了html标签......但还不确定如何指向特定的块....例如$ xml-> asXML(block)显示1

got it

$xml->block->asXML() 

works

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

我还是想知道是否有更好的方法。