Jump to content

simplexml, saving < and >


Aimar

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/194294-simplexml-saving-and/
Share on other sites

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?

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.

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)); 
  }
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.