Php 解析xml文件时保留html内容
我有一个xml文件Php 解析xml文件时保留html内容,php,xml,Php,Xml,我有一个xml文件 <text> <defalut>This file has the following features:</defalut> <value> <ul> <li><info>CSS text formatting </info></li> <li><info>Text
<text>
<defalut>This file has the following features:</defalut>
<value>
<ul>
<li><info>CSS text formatting </info></li>
<li><info>Text loaded from a XML</info></li>
<li><info>Scrolls with easing</info></li>
<li><info>Mouse wheel supported</info></li>
<li><info>HTML supported</info></li>
<li><info>Click on the bar to move the handle to that point</info></li>
<li><info>Supports images</info></li>
<li><info>The scrollbar hides if not needed</info></li>
<li><info>The scrollbar resizes proportonal to the text sizeq</info></li>
</ul>
</value>
<tittle>Lorem Ipsum</tittle>
</text>
但我只得到了绳子。
如何在结果中保留html标记
如果iam正在解析
标记,我获取的内容没有
和
我如何获取
标记中的完整html内容
提前感谢我不能百分之百肯定我了解您的问题,但我的直觉告诉我您正在寻找CDATA区域:
$nodes = $xml->xpath('//text/value');
<text>
<defalut>This file has the following features:</defalut>
<value>
<![CDATA[
<ul>
<li><info>CSS text formatting </info></li>
<li><info>Text loaded from a XML</info></li>
<li><info>Scrolls with easing</info></li>
<li><info>Mouse wheel supported</info></li>
<li><info>HTML supported</info></li>
<li><info>Click on the bar to move the handle to that point</info></li>
<li><info>Supports images</info></li>
<li><info>The scrollbar hides if not needed</info></li>
<li><info>The scrollbar resizes proportonal to the text size</info></li>
</ul>
]]>
</value>
<tittle>Lorem Ipsum</tittle>
</text>
解析文件后,它将被加载到DOM表示中,DOM表示是所有节点的内存树。要恢复HTML,必须序列化包含XML的节点。使用asXML(),simplexmlement::asXML-返回基于SimpleXML元素的格式良好的XML字符串
$result = $xml->xpath('//text');
echo $result[0]->asXML();
不需要CDATA
我们可以简单地使用
$result = $xml->xpath('//text');
echo $result[0]->asXML();
当我尝试$xml\u str1=file\u get\u contents($file)时,它将按原样加载HTML内容$xml_str=$xml_str.$xml_str1$xml=simplexml\u load\u字符串($xml\u str)$nodes=$xml->xpath('//text');我正在获取结果数组([0]=>SimpleXMLElement对象([defalut]=>此文件具有以下功能:[value]=>SimpleXMLElement对象()[Title]=>Lorem Ipsum])我使用了CDATA的第一个解决方案
$result = $xml->xpath('//text');
echo $result[0]->asXML();
$result = $xml->xpath('//text');
echo $result[0]->asXML();