Aimar Posted March 5, 2010 Share Posted March 5, 2010 Hi there, I have small script like this: $lines->section[4]->page[2]->texts->pageText[1] = "<![CDATA[$new_value]]>"; file_put_contents('../25257_main.xml', $lines->asXml()); Problem is - it's not saving <![CDATA... - it converts "<" and ">" to entities ">" Is there any wayaround? I need it to be saved with < > Thanks in advance, Aimar Quote Link to comment https://forums.phpfreaks.com/topic/194294-simplexml-saving-and/ Share on other sites More sharing options...
premiso Posted March 5, 2010 Share Posted March 5, 2010 I do not think it would be valid XML if you were to do the actual < and >. As it would break syntax. It has to be the entity. Instead of trying to get it to be the actual < why not just decode the entitiy on retrieval / display using html_entity_decode? Quote Link to comment https://forums.phpfreaks.com/topic/194294-simplexml-saving-and/#findComment-1022143 Share on other sites More sharing options...
Aimar Posted March 5, 2010 Author Share Posted March 5, 2010 I do not think it would be valid XML if you were to do the actual < and >. As it would break syntax. Acutally, it doesn't break syntax, so it's not a problem. Instead of trying to get it to be the actual < why not just decode the entitiy on retrieval / display using html_entity_decode()? Can't do that - .xml file is being loaded by flash website (.swf) - so best solution for it would be to save it with < > in .xml before flash reads it. Maybe there's another function in php which could save it without dropping < > chars? Or any other way around? Thanks for any hint. Quote Link to comment https://forums.phpfreaks.com/topic/194294-simplexml-saving-and/#findComment-1022151 Share on other sites More sharing options...
Aimar Posted March 6, 2010 Author Share Posted March 6, 2010 OK, problem solved with this class: class SimpleXMLExtended extends SimpleXMLElement { public function addCData($cdata_text) { $node= dom_import_simplexml($this); $no = $node->ownerDocument; $node->appendChild($no->createCDATASection($cdata_text)); } } Quote Link to comment https://forums.phpfreaks.com/topic/194294-simplexml-saving-and/#findComment-1022299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.