Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extends SimpleXMLElement to support writing CDATA
<?php
class SimpleXMLExtended extends SimpleXMLElement
{
// Inspired by: https://stackoverflow.com/questions/6260224/how-to-write-cdata-using-simplexmlelement/6260295
public function addCDATA($string)
{
$node = dom_import_simplexml($this);
$nodeOwner = $node->ownerDocument;
$node->appendChild($nodeOwner->createCDATASection($string));
}
public function appendChildWithCDATA($key, $value)
{
$this->addChild($key);
$this->{$key}->addCData($value);
}
}
@vicgonvt

This comment has been minimized.

Copy link

@vicgonvt vicgonvt commented Aug 11, 2018

Clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment