我使用此代码编辑XML文件与CDATA
$xml = simplexml_load_file($xmlfile) or die ("Unable to load XML file!");
$event->title = $newtitle;
$event->description = $newdescription;
file_put_contents($xmlfile, $xml->asXML());
我想添加一个CDATA在description.I使用该代码
$event->description = '<![CDATA['.$newdescription.']]>';
但在XML中的<
和>
转换为<
和>
。如何保留CDATA
原样。是否有其他编辑方法。提前感谢。
其实我想编辑这个XML文件
<events date="06-11-2010">
<event id="8">
<title>Proin porttitor sollicitudin augue</title>
<description><![CDATA[Lorem nunc.]]></description>
</event>
</events>
<events date="16-11-2010">
<event id="4">
<title>uis aliquam dapibus</title>
<description><![CDATA[consequat vel, pulvinar.</createCDATASection></description>
</event>
<event id="1"><title>You can use HTML and CSS</title>
<description><![CDATA[Lorem ipsum dolor sit amet]]></description></event></events>
ID为
谢谢Cez.I编辑我的问题。我想编辑与相应的id的内容。你可以告诉它是怎么回事? – Warrior 2010-11-05 10:11:29
@THOmas:我已经添加了一个基于XML的示例。希望它应该指向正确的方向 – Cez 2010-11-05 11:05:04
是他们的任何方式来链接xpath和xquery或dom_import_simplexml – Warrior 2010-11-05 11:41:35