當我解析XML文檔時,我需要保存<![CDATA[]]>
標記。SimpleXML:在節點值中處理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文件的例子嗎? –