【发布时间】:2017-06-22 13:41:14
【问题描述】:
解析XML文档时需要保存<![CDATA[]]>标签。
例如,我有节点:
<Dest><![CDATA[some text...]]></Dest>
在 xml 文件中可能存在没有 CDATA 的节点。
然后我循环处理所有节点:
$dom = simplexml_load_file($path);
foreach($dom->children() as $child) {
$nodeValue = (string) $child;
}
因此,当我在上面的示例中处理节点时 - $nodeValue = some text...
但我需要$nodeValue = <![CDATA[some text...]]>
有什么办法吗?
文件示例:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<Params>
<param>text</param>
<anotherParam>text</anotherParam>
</Params>
<Content>
<String>
<Source>some another text</Source>
<Dest>some another text 2</Dest>
</String>
<String>
<Source>some another text 3</Source>
<Dest><![CDATA[some text...]]></Dest>
</String>
</Content>
</Root>
【问题讨论】:
-
你能举一个XML文件的例子吗?